What this Python code-output question tests
This is a hard Python question that requires close reading of language semantics and careful execution tracing. It rewards the ability to predict runtime behaviour without running the code—a skill that matters in both interview settings and production debugging.
To solve problems like this, you need to mentally execute the code step by step, paying attention to scope, binding, control flow, and any subtle interactions between Python's dynamic typing and namespace rules. The question may involve edge cases around name resolution, mutation, or the order in which statements execute.
- Python's name-binding and scope rules
- Mutation vs. reassignment
- Order of evaluation and side effects
- Exception types and when they are raised