What this Python name-binding interview question tests
This is a hard Python question that probes deep familiarity with how the interpreter manages module identity and variable scoping. It rewards candidates who understand the distinction between local, module, and built-in namespaces, and how Python's name-resolution order affects what gets looked up and printed.
Questions like this typically appear in coding rounds at firms that value precision and attention to detail. They test whether you can trace through Python's attribute and variable lookup rules without guessing, and whether you can reason about the runtime context in which code executes. The question hinges on understanding a specific Python mechanism that many junior developers misunderstand or overlook.
- Namespace hierarchy and the LEGB rule
- Module-level vs. local scope binding
- Python's name-resolution order in nested contexts