nonlocalIntermediate Playground

Declares a variable inside a nested function as belonging to the enclosing scope

Python Playground
Output
Click "Run" to execute your code

nonlocal targets the nearest enclosing function scope. global targets the module scope. They affect different variables.

Challenge

Try modifying the code above to explore different behaviors. Can you extend the example to handle a new use case?