this code
def gen(x):
def f():
return x
return f
print(gen(1)())
works well.
but when i run this code,
def gen(x):
def f():
x += 1
return x
return f
print(gen(1)())
I got an error shows that
UnboundLocalError: local variable 'x' referenced before assignment
what happened to it? and How to understand the closure of python3 .