Let's break down the code line by line to explain what's happening:
✅ This creates a list with three zeroes:
✅ You're replacing the first element (x[0]) with a list containing 1.
So now:
✅ You're making x[1] refer to the same list object as x[0].
Both x[0] and x[1] now point to [1]:
✅ This changes the first element inside the inner list at x[0] to 99.
But since x[1] is also pointing to the same list, the change reflects there too!
So now:
✅ Final Output:
Key Concept:
This demonstrates aliasing or shared references — both x[0] and x[1] refer to the same list object in memory. Modifying one affects the other.


0 Comments:
Post a Comment