References and Copies
This is the single most surprising rule in both languages, and it explains bugs that otherwise look like magic.
When you assign a number or a string to a new variable, the value is copied. When you assign a list, array, dictionary, or object, the value is not copied. Both names point at the same object in memory.
✦ Two names, one object
y = x does not mean 'make me a copy of x'. It means 'let y also refer to whatever x refers to'. For a number that distinction is invisible. For a list it is everything.
When you genuinely want an independent copy, ask for one explicitly.
Mark this lesson complete
Signed in, your progress follows you to every device.