What this Python name-scope interview question tests
This is a medium-difficulty Python question that probes your understanding of module-level execution, the __name__ variable, and how Python distinguishes between script execution and module import. It's a common interview checkpoint because it separates candidates who have internalized Python's execution model from those relying on rote memorization.
To answer correctly, you need to trace through what happens when a script runs directly versus when it is imported, and understand how the __name__ builtin changes in each context. The question rewards careful reading of the code flow and attention to which blocks actually execute.
- The
__name__ variable and its values in different execution contexts - Module initialization and the import system
- Conditional execution with
if __name__ == '__main__': - Order of execution when scripts reference multiple files