nonlocal — Expert Playground
Declares a variable inside a nested function as belonging to the enclosing scope
Python Playground
Output
Click "Run" to execute your codenonlocal variables use cell objects shared between the enclosing and inner function. Both access the cell via LOAD_DEREF/STORE_DEREF opcodes. The cell is stored in __closure__.
Challenge
Try modifying the code above to explore different behaviors. Can you extend the example to handle a new use case?