Mutability and aliasing

A variable is a name for an object, not a box holding a copy. After b = a, both names point at the same list. Change it through b and you see the change through a. a is b checks whether two names share one object.

Function arguments work the same way. A function that calls .append or .clear on a list argument changes the caller's list.

The famous trap is building a grid with [[0] * 3] * 3. The outer * 3 repeats a reference to the same inner list three times. Set one cell and the whole column changes. Build each row separately with a comprehension instead: [[0] * 3 for _ in range(3)].

This shows up all the time in the Debugging challenges: a "copy" that isn't, or a function that changes its input when nobody expected it to.

Run it, then print grid[0] is grid[1] for both grids.