What this Python reference-count question tests
This is a medium-difficulty question that probes your understanding of Python's memory model, specifically how the interpreter tracks object lifecycle through reference counting. It's the kind of question that separates candidates who use Python fluently from those who rely on intuition alone.
To answer correctly, you need to trace through a code snippet and account for every binding that points to an object—explicit variable assignments, function arguments, return values, and implicit references held by the runtime itself. The skill being tested is the ability to reason precisely about when an object is created, how many references exist at a given point, and what the garbage collector will or will not clean up.
- Object identity and
id() - Variable binding vs. object ownership
- How function calls and scope affect reference counts
- Built-in types and their internal reference behaviour