Can anyone tell me why the following code error?
My guess is, the inner function is somehow detecting a 'new' variable declaration, (i have 'x' on a left side on inner() ).
While it fails because this 'x' appears first on the right side.
Is this correct?
Am I wrong expecting it to behave normally (i.e Increment the value of x).
In any other context, x can be accessed from the inner function. The only problem happens if I ever put that x on a left side.
def outer(x):
def inner():
x = x + 1
return x
return inner()
outer(1)
UnboundLocalError: local variable 'x' referenced before assignment