The global statement refers to the outermost variable. The nonlocal statement refers to a variable one outside the function.
#
#Interactive mode>>>To
#You can do it by copying.
#
interval= 0 # <---The global statement refers to the outermost variable.
def Make a counter():
Current value= 0 # <---The nonlocal statement refers to a variable one outside the function.
def count():
global interval
nonlocal current value
Current value=Current value+interval
return current value
return count
Count=Make a counter()
#interval=Since it is 0, it remains 0
Count()
Count()
Count()
#interval=If set to 1, it will be incremented by 1.
interval= 1
Count()
Count()
Count()
>>> #interval=Since it is 0, it remains 0
>>>Count()
0
>>>Count()
0
>>>Count()
0
>>>
>>> #interval=If set to 1, it will be incremented by 1.
>>>interval= 1
>>>Count()
1
>>>Count()
2
>>>Count()
3
>>>
Other uses for functions defined within a function are "decorator" and "currying, partial application".