Best afterValues and names
Aliasing: two names, one list
Assigning one list to another name does not make a copy — both names point at the same list object. Change it through one name and the 'other' changes too. The matching reference ids in the state pane make the shared identity literal. Watch the backup get corrupted.
Make a backup of the scores list, then add 30 to the original — the backup should keep the first two scores.
Assignment doesn't copy a list execution-derived · CPython
variables
state after line 1 runs
| variable | value |
|---|---|
scores | [10,20] |
step 1 / 3
Click a line, drag the slider, or use the ← → keys.
What you are looking at
Watch backup when only scores is touched — and watch the ref ids.
- Buggy —
backup = scoresbinds a second name to the same list (equal ref ids prove it). Appending30toscoreschangesbackuptoo — it was never a separate copy. - Procedural —
backup = scores[:]slices out a brand-new list, so the two are independent (no shared ref id). Now appending toscoresleavesbackupat[10, 20].
Every state you see came from running the program under CPython's tracer at build time — see how GlassBox stays honest.