I found some questions asking about TypeError: 'tuple' object does not support item assignment on SO, but still, I'm confused about this:
Consider the code snippet:
>>> a = ([],[])
>>> a[0].append(1) # 1
>>> a
([1], [])
>>> a[0] += [2]
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
a[0] += [2]
TypeError: 'tuple' object does not support item assignment # 2
>>> a
([1, 2], []) # 3
>>>
My questions are:
- tuples are immutable, but
1successfully changed its value.Why?(I know I dont really understand python immutability..) - If
1is accepted, what's the reason that2raiseTypeError? - In
3,agets modified, then what's the point raising aTypeError?
Thank you