What this Python language-knowledge question tests
This is a medium-difficulty question designed to probe your understanding of Python's scoping rules, variable binding, and how the interpreter resolves names at runtime. It rewards careful attention to how Python evaluates expressions in different contexts.
To work through this kind of problem, you need to trace through the code mentally, paying close attention to the order of execution, whether names are bound in local or outer scopes, and what values are actually accessible at each point. The question may hinge on a subtle interaction between how Python handles references and when it raises exceptions.
- Local, enclosing, and global scope resolution (LEGB rule)
- When Python raises
NameError and UnboundLocalError - Late binding in closures and nested functions
- Variable assignment and name rebinding