nonlocal Scope

Let's briefly understand the nonlocal scope in python.

Python 3 added a new keyword called nonlocal. The nonlocal keyword adds a scope override to the inner scope. We can read all about it in PEP 3104. This is best illustrated with a couple of code examples. One of the most common examples is to create function that can increment:

Get hands-on with 1200+ tech skills courses.