nonlocalEasy Playground

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

Python Playground
Output
Click "Run" to execute your code

nonlocal lets an inner function modify a variable from its enclosing function's scope, not the global scope.

Challenge

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