Hi Pythonistas!
Let me tell you a quick story. My friend came to me last day, eyes gleaming like they’d found a bug in the matrix.
He show me a code:
>>> a = (1, 2, 3)
>>> a = a + (4, 5)
>>> a
(1, 2, 3, 4, 5)
"See? Tuples are not really immutable! I just changed it!"
Mind blown. Tuple rule violated. Right? Well... not really. Let's slow down and decode the illusion.
What’s Actually Happening?
Let’s read the lines again:
a = (1, 2, 3)
a = a + (4, 5)
This might look like we’re modifying a, but what’s actually happening is:
A new tuple (4, 5) is created.
Python concatenates (1, 2, 3) and (4, 5) → resulting in (1, 2, 3, 4, 5).
The name a is now pointing to this new tuple.
The original (1, 2, 3) tuple is untouched (and probably garbage collected if not used elsewhere).
This is not mutation. This is reassignment.
Let’s Prove It With id()
>>> a = (1, 2, 3)
>>> id(a)
132227033277760
>>> a = a + (4, 5)
>>> a
(1, 2, 3, 4, 5)
>>> id(a)
132227033383136
>>>
As you can see, the memory address (object id) changed — meaning it’s a completely different object.
So What Does “Immutable” Really Mean?
Once created, the object cannot be changed in place.
>>> a = (1, 2, 3)
>>> a[0] = 10
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment
>>>
You cannot mutate its contents. But you can reassign the variable a to a different object — just like any variable in Python.
Takeaway
✅ a = a + (4, 5) creates a new tuple.
❌ It does not mutate the original tuple.
✅ Tuples remain proudly immutable.
Immutability is powerful — it allows tuples to be:
- Used as dict keys
- Safely shared between threads
- Hashed and cached efficiently
So yes — tuples are immutable.