First page Back Continue Last page Overview Graphics

Tuples Special Cases

>>> single = (1)

>>> type(single)

<type 'int'>

>>> single = (1,)

>>> type(single)

<type 'tuple'>

>>> single

(1,)

Immutable, aren't they?

>>> galileo = ([],)

>>> galileo[0].append("And yet it moves!")

>>> galileo

(['And yet it moves!'],)

But this isn't possible:

>>> galileo[0] = [3434,3434]

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

TypeError: 'tuple' object does not support item assignment

It doesn't work with (1), because this is not a tuple instance but

an expression, i.e. a 1 in parenthesis.