Scope determines where names are visible and how Python resolves them. Inside a function, Python searches Local, Enclosing function, Global, then Built-ins (LEGB), stopping at the first match. section 6.5
Use these distinctions when tracing a name:
- Indentation organizes Python code but does not itself create variable scope; functions do. section 6.5
Closures preserve enclosing state
A nested function can retain access to an enclosing variable after the outer function returns. With nonlocal call_counter, each call updates that retained state, producing counts from 1 through 9.




















