Even though the tuples are immutable, the object inside it can be mutuable
Since in >>> t = (1, 2, [3, 4])
the list is mutable so you can change the list value with Augmented assignment. +=
but then the exception is raised.
here the t[2] list is modified as you can see
t =(1,2,[3,4])
>>> id(t[2])
38073768
>>> t[2] += [5,6]
Traceback (most recent call last):
File "<input>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment
>>> t[2]
[3, 4, 5, 6]
>>> id(t[2])
38073768
As you can see the t[2] id never gets changed.
As for the second case: t[2] = t[2] + [5,6]
- it creates a new list and then assign it to t[2]
>>> li = [1,2]
>>> id(li)
38036304
>>> li = li + [3,4]
>>> id(li)
38074368
>>> li += [5,6]
>>> id(li)
38074368
As you can see List = list + []
is a new list with a different id. and as the tuple is immutable t[2] doesn't get assigned to a new object in the second case