Tuples and immutability
Eric Jacoboni
eric.jacoboni at gmail.com
Thu Feb 27 11:01:39 EST 2014
Hi,
I'm using Python 3.3 and i have a problem for which i've still not found
any reasonable explanation...
>>> a_tuple = ("spam", [10, 30], "eggs")
>>> a_tuple[1] += [20]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment
Ok... I accept this message as += is a reassignment of a_tuple[1] and a
tuple is immutable...
But, then, why a_tuple is still modified?
>>> a_tuple
('spam', [10, 30, 20], 'eggs')
I get a TypeError for an illegal operation, but this operation is still
completed?
More information about the Python-list
mailing list