Unable to bind the local x
of f()
to the global var x
of the nested g()
. Why?
def f():
x=0
def g():
global x
x+=1
print(x)
g()
g() # added to make seemingly more practical
-
>>> f()
...
NameError: global name 'x' is not defined