1.Variables, objects, names, and references
A 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.
Key features
- = binds a name to an object; it never copies
- id() reports which object a name is bound to
- a is b compares identity, a == b compares value
- Two names on one list share every mutation
- Rebinding moves one name; mutating changes the object
Mutable, and usable as a key
- 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.
Command
retry_budget = [1, 2, 4] # bind a name to a list object
backup_budget = retry_budget # second name for the SAME object
backup_budget is retry_budget # True — one object, two names
backup_budget = [1] # rebind: moves only backup_budgetAssignment binds a name; it never copies an object. Two names on one list means an append through either is visible through both.