Tuple Semantics - Rationale'?
Chris Barker
chrishbarker at home.net
Wed Jul 11 19:01:47 EDT 2001
Tim Daneliuk wrote:
> From what I've read, to force the data structure to be maintained correctly,
> I have to add a trailing comma to the single arg pair like this:
>
> )
> (name-n, descrip-n),
> ( (argA-1, argB-1), )
> ),
That's right
> 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 used for other kinds of groupings as well. Would
(a*b) be a single value or a one-tuple? It's unfortunate, but there are
only so many kinds of brackets on a keyboard.
> Supposed I did want 0 argument pairs in that tuple, but I wanted to prepare
> the way for adding some later. Would I use:
>
> (()), (), ((,)) ???
tuples are immutable, so you can't add anything later anyway. Perhaps
you'd be better off with lists here.
-Chris
--
Christopher Barker,
Ph.D.
ChrisHBarker at home.net --- --- ---
http://members.home.net/barkerlohmann ---@@ -----@@ -----@@
------@@@ ------@@@ ------@@@
Oil Spill Modeling ------ @ ------ @ ------ @
Water Resources Engineering ------- --------- --------
Coastal and Fluvial Hydrodynamics --------------------------------------
------------------------------------------------------------------------
More information about the Python-list
mailing list