Question about tuple lengths
iddw at hotmail.com
Wed Dec 14 21:10:15 CET 2005
On Wed, 14 Dec 2005 12:58:16 -0500 in comp.lang.python, Jean-Paul
Calderone <exarkun at divmod.com> wrote:
>It's the comma that makes it a tuple. The parenthesis are only required in cases where the expression might mean something else without them.
That's almost true. Consider:
>>> t2 = (1,2) # 2 element tuple
>>> t1 = (1,) # 1 element tuple
>>> t0 = (,) # 0 element tuple?
File "<stdin>", line 1
t0 = (,)
SyntaxError: invalid syntax
>>> t0 = () # Guess not, try parens with no comma
>>> print t0, t1, t2
() (1,) (1, 2)
>>> print type(t0), type(t1), type(t2)
<type 'tuple'> <type 'tuple'> <type 'tuple'>
>>> print len(t0), len(t1), len(t2)
0 1 2
Change is inevitable, progress is not.
More information about the Python-list