Tuple Semantics - Rationale'?

Quinn Dunkan quinn at yak.ugcs.caltech.edu
Wed Jul 11 16:04:21 EDT 2001


On 11 Jul 2001 19:00:01 GMT, Tim Daneliuk <tundra at tundraware.com> wrote:
>And that works fine.  But *why* is the trailing comma designed into the
>language semantics this way.  I've been scratching my head and cannot come
>up with a rationale'.  It seems to me that the explicit use of the parens
>should be telling python that I want the second entry in each data
>structure to be a *tuple* of 0 or more tuples.

Because parens are overloaded.  Consider:

print (10 + 5) * 3

Do you expect

45

or

(15, 15, 15)

?


>Supposed I did want 0 argument pairs in that tuple, but I wanted to prepare
>the way for adding some later.  Would I use:
>
>        (()), (), ((,)) ???

Did you try it?  According to the documentation you use

((), (), ())

The documentation also recognizes that () vs. (one_elt,) vs. (two, elts) is
ugly, but there's no getting around it unless we get keyboards with more
bracket keys.

Large complicated data structures of nested tuples might be a mistake.  Tuples
and python's simple pattern matching can be handy for small ad hoc types, but
don't forget about classes.



More information about the Python-list mailing list