ReferenceKeywords
nonlocal
Lets a nested function rebind a name in the function around it.
Signature
nonlocal nameReturns
Nothing.
Example
Python
def make_counter():
count = 0
def increment():
nonlocal count
count += 1
return count
return increment
counter = make_counter()
print(counter(), counter())Output
1 2