What’s happening?
1️⃣ t is a tuple
t = (1, 2, 3)Tuples are immutable sequences.
2️⃣ __mul__() is the magic method for *
t * n internally calls:
So this:
t * 0and this:
t.__mul__(0)are exactly the same.
3️⃣ Multiplying a tuple by 0
Rule:
Any sequence × 0 → empty sequence
So:
(1, 2, 3) * 0becomes:
()✅ Final Output
()⚠️ Important Concept (Interview Favorite)
-
The tuple itself is not modified
-
A new empty tuple is created
-
This works for:
-
lists
-
tuples
-
strings
-
Example:
One-line takeaway
__mul__(0)returns an empty sequence of the same type


0 Comments:
Post a Comment