~/talk

Variables and objects in Python: it's pointers all the way down

Talkat PyCascades 2026 · 2026-03-21..03-22· [python, compilers-and-language-design]
slides:none on file

Demonstrates five gotchas about Python references: assignment never copies, mutations change shared objects, function arguments are just bindings so in-place updates modify callers, self‑concatenating lists and dict.fromkeys create multiple references to one list (dict.fromkeys bug), and default mutable arguments leak state (default mutable arg). Shows failing code and fixes: use list/dict comprehensions to create distinct objects, or copy with list() in __init__; explains identity vs equality and when to return a new object versus mutating in place.

AI-written summary · about

  1. 0:00Python mental models
  2. 0:51Python gotchas explained
  3. 3:54Variables as pointers
  4. 6:12Mutations vs assignments
  5. 8:32Equality vs identity
  6. 10:12Python assignment features
  7. 12:57Object references
  8. 15:15Fixing list of lists gotcha
  9. 17:14Fixing dict.fromkeys gotcha
  10. 18:23Fixing to-do list class gotcha
  11. 21:19Recap of variables and objects
  12. 24:07Why Python works this way
  13. 26:14Closing thoughts
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.