Caffeinated Coder
Book an appointment
Lesson 28 · Under the hood

Names, objects and references

In Python a variable is not a box that holds a value. It is a name in a namespace that refers to an object on the heap, and an object can have many names. Step through a seven-line program, refs.py, and watch the arrows: two names share one list, a change through one name shows through the other, == and is give different answers, and CPython frees the list the moment its last reference goes away.

14 min8 steps5 questionsAdvanced
Fig 28 · Interactive
Loading figure…
or ← →

Quiz Unlocks after the last step.