What this Python scoping and execution-order question tests
This is a medium-difficulty Python question that probes your understanding of name resolution, scope binding, and the order in which Python evaluates assignments and function definitions. It rewards precise mental execution over guessing.
To solve it, you need to trace how Python builds its namespace at module load time, distinguish between the moment a function is defined and the moment it is called, and understand how variable lookups resolve across local, enclosing, and global scopes. The question tests whether you can reliably predict runtime behaviour without running the code — a skill that matters when debugging or reasoning about code correctness in interviews.
- Global vs. local scope and the LEGB rule
- Closure and late binding of free variables
- The timing of function definition vs. execution
- How Python resolves names at runtime