
139
LEWait… aren’t tuples immutable? 😵
Yes, tuples are immutable.
But immutability only means you cannot change what the tuple holds —
you cannot replace its elements.
However, if a tuple contains a mutable object (like a list),
that object itself can still change.
In this case:
a = (1, [2, 3])
The tuple has two elements:
Integer 1
A list [2, 3]
When we do:
a[1].append(4)
We are NOT modifying the tuple.
We are modifying the list inside it.
So the final output becomes:
(1, [2, 3, 4])
This is a classic interview trap and a deep Python concept.
Immutable container ≠ immutable contents 🧠💡
Understanding this prevents serious bugs in real-world applications.
Save this — this is advanced Python knowledge 💾🐍
#Python #PythonEdgeCases #AdvancedPython #CodingTricks #ProgrammingLife
@learninstudy










