[Python-ideas] Python Users Aren't Perfect

Ben Finney ben+python at benfinney.id.au
Fri Dec 16 03:23:17 CET 2011


Ned Batchelder <ned at nedbatchelder.com>
writes:

> This is another place where Python is inconsistent. We're told, "lists
> are for homogenous sequences of varying length, like a C array; tuples
> are for heterogenous aggregations of known length, like a C struct."

I think that's a poor rendition of the distinction. Rather, what I
advise is: if the *meaning* of an item depends on its position in the
sequence (like with a C struct), use a tuple. If the meaning of an item
is unaffected by its position in the sequence, use a list.

> Then we define a function foo(*args), and Python gives us a tuple! :-(

Yes, exactly: the positional arguments to the function are *not* a
homogeneous sequence, so a list doesn't connote the right thing. The
position is important – we call them “positional arguments” – so a tuple
makes sense.

-- 
 \     “I am the product of millions of generations of individuals who |
  `\      each fought against a hostile universe and won, and I aim to |
_o__)              maintain the tradition.” —Paul Z. Myers, 2009-09-12 |
Ben Finney




More information about the Python-ideas mailing list