What this Python language-knowledge question tests
This is a medium-difficulty question that probes your understanding of Python's scoping rules, object mutability, and how the interpreter handles variable binding in different contexts. It rewards careful reading of code over guesswork.
To solve problems like this, you need to trace through the code step-by-step, paying attention to where variables are defined, how they are reassigned, and whether you are working with mutable or immutable types. Understanding the difference between name binding and object identity is critical. Interviewers use these questions to check whether you can predict program behaviour without running it—a skill that translates directly to debugging and reasoning about code during implementation rounds.
- Variable scoping and the LEGB rule (local, enclosing, global, built-in)
- Mutable vs. immutable objects and aliasing
- Rebinding vs. mutation
- How Python evaluates print statements and expression order