Why tuples ???

Michael Hudson mwh21 at cam.ac.uk
Mon Apr 23 13:05:15 EDT 2001


"Fredrik Lundh" <fredrik at pythonware.com> writes:

> Thomas Weidner wrote:
> > I started lerning Python and discovered tuples, but why do they exist ?
> > What's the difference from a list ?
> 
> did you remember to check the FAQ?
> 
>     http://www.python.org/doc/FAQ.html#6.15
>     Q. Why are there separate tuple and list data types?
> 
> also consider this code fragment:
> 
> >>> T = (1, 2, 3)
> >>> L = (1, 2, 3)

How did you manage that typo?  I can't believe you cooked up the whole
session - unless you can type tracebacks from memory, which would be
scary...

> >>> D = {}
> >>> D[T] = "spam"
> >>> D[L] = "spam"
> Traceback (innermost last):
>   File "<stdin>", line 1, in ?
> TypeError: unhashable type
> 
[snip]

Cheers,
M.

-- 
 Very clever implementation techniques are required to implement this
 insanity correctly and usefully, not to mention that code written
 with this feature used and abused east and west is exceptionally
 exciting to debug.       -- Erik Naggum on Algol-style "call-by-name"



More information about the Python-list mailing list