def counter(x):
def _cnt():
#nonlocal x
x = x+1
print(x)
return x
return _cnt
a = counter(0)
print(a())
Above code gives the following error
UnboundLocalError: local variable 'x' referenced before assignment
Why this is not able to create a new object with value 'x+1' in the namespace of _cnt and bind it to x. we will have reference x in both function namespaces