Names and assignment

A variable is a name bound to an object. b = a doesn't copy anything. It makes b a second name for the same object. If that object can change, like a list, a change through b shows up in a. This surprises people more than anything else in Python.

For an immutable value like an int or a string, x += 1 builds a new object and rebinds x. Other names keep the old value.

You can assign several names at once: x, y = 1, 2. The right side is built first, so a, b = b, a swaps two values without a temporary. Interviewers like seeing this.

Augmented assignment works for most operators: +=, -=, *=, //=.

Run it, then change b = a to b = a.copy().