Tuples and immutability
Eric Jacoboni <eric.jacoboni at gmail.com>:
>>>> a_tuple += 
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> TypeError: 'tuple' object does not support item assignment
> But, then, why a_tuple is still modified?
That's because the += operator
1. modifies the list object in place
2. tries to replace the tuple slot with the list (even though the list
It's Step 2 that raises the exception, but the damage has been done
One may ask why the += operator modifies the list instead of creating a
new object. That's just how it is with lists.
>>> a_tuple = a_tuple