I am trying to understand the following error in python:
In []: tup = tuple(['foo', [1,2], True])
In []: tup[1]+=[2]
This leads to the following error:
TypeError: 'tuple' object does not support item assignment
I understand this is because tuples are not mutable. However, the second element of the tuple is now mutated in the manner I desired.
In []: tup
Out[]: ('foo', [1, 2, 2], True)
Can someone please explain what happened here. I got an error but the code did exactly what I wanted. What did the code fail to accomplish that is being shown by the error?
Also, I understand that the append method can accomplish the same.
In []: tup[1].append(2)
In []: tup
Out[]: ('foo', [1, 2, 2, 2], True)
But I still want to understand what happened in the first case above.