How to Stop Python Lists from Lying to You
You changed a list. You only changed one list. But somehow, both lists changed.
You stare at the screen. Nothing makes sense. Cold pizza, 14 open Stack Overflow tabs, and your laptop battery sitting at 11%.
Here’s the thing — this isn’t a bug. It’s Python working exactly as it’s designed to. And once you get it, you’ll never fall for it again.
The “Box” vs “Label” Problem
Most beginners think of a variable like a box that holds data. In that mental model, copy = original means you're putting the same data into a new box. Change one box, the other doesn't care.
But in Python, variables are labels — not boxes.
When you write copy = original, you're not duplicating the list. You're sticking a second label onto the same object sitting in memory. Both names point to the exact same thing.
Here’s what that looks like visually:
...
Copyright of this story solely belongs to hackernoon.com. To see the full text click HERE