Variables, objects, names, and references
corebeginnerA name is a label you attach to an object. Assignment attaches the label; it never copies the object. Two names can label one object, so a change made through one name is visible through the other.
Think of it as
Objects sit in memory. Names are sticky labels you put on them. An = moves a label onto an object; it never clones what the label is stuck to.
What we're doing: Show that a second name does not make a second list, and that rebinding differs from mutating.
- 1
- Builds one list object and binds the name retry_budget to it.
- 2
- Binds a second name to that same object. No list is copied here.
- 4–5
- Both ask the same question — same object? — and both answer yes.
- 7
- Mutates the shared list through the second name.
- 8
- retry_budget shows the 8 as well, because there was only ever one list.
- 10
- Rebinding, not mutating: only backup_budget moves, onto a new list.
- 11–12
- retry_budget still holds the original list, and the two names now differ.
True
True
[1, 2, 4, 8]
[1, 2, 4, 8]
FalseWhy this works: Assignment binds a name to an object rather than copying it, so line 2 gives one list a second name. Mutating through either name changes that single object. Rebinding on line 10 points one name at a different object and leaves the other name where it was.
A shallow copy still shares what is inside
Wrong
Better
What you see: The wrong version prints {'retries': [1, 2, 4, 8]} — the defaults changed even though a copy was made.
Why: copy.copy builds a new dict, but binds its values to the same objects the original holds. The inner list is shared, so appending through the copy is visible through the original. copy.deepcopy rebuilds the nested objects too.
- Two name labels sit on the left, one above the other: retry_budget and backup_budget.
- An arrow runs from each label to a single box on the right holding the list [1, 2, 4].
- There is one object and two names, so id(retry_budget) and id(backup_budget) are equal.
- Appending through either name changes that one shared list, so the other name sees it too.
Mutable, and usable as a key
Together

