Step 1: Creating the tuple
t = (1, 2, [3, 4])Here, t is a tuple containing:
1 → integer (immutable)
2 → integer (immutable)
[3, 4] → a list (mutable)
So the structure is:
t = (immutable, immutable, mutable)Step 2: Understanding t[2] += [5]
t[2] += [5]This line is equivalent to:
t[2] = t[2] + [5]Now two things happen internally:
๐ First: The list inside the tuple is modified
Because lists are mutable, t[2] (which is [3, 4]) gets updated in place to:
[3, 4, 5]๐ Second: Python tries to assign back to the tuple
After modifying the list, Python tries to do:
t[2] = [3, 4, 5]But this fails because tuples are immutable — you cannot assign to an index in a tuple.
❌ Result: Error occurs
You will get this error:
TypeError: 'tuple' object does not support item assignment❗ Important Observation (Tricky Part)
Even though an error occurs, the internal list actually gets modified before the error.
So if you check the tuple in memory after the error, it would conceptually be:
(1, 2, [3, 4, 5])But print(t) never runs because the program crashes before that line.
✅ If you want this to work without error:
Use this instead:
Output:
(1, 2, [3, 4, 5])


.png)








.png)
.png)

.png)



.png)
