here is my code:
def f(x):
def g(n):
if n < 10:
x = x + 1
g(n + 1)
g(0)
When I evaluate f (0), there will be an error "referenced before destination".
However, when I use "print x" instead of "x = x + 1", it will work.
It seems that in the g area, I can only use x as a βuseβ, but not a βbindingβ. I think the problem is that f passes g only the value VALUE x.
Do I understand this correctly? If not, can someone explain why the left side of "x = x + 1" is not defined before the link?
thanks
source
share