I totally understand the idea of different scopes in Python but I can't understand this code clearly so I'd be pleased if someone can explain it to me, the return in line 18 what does it mean? shouldn't it be return g() for example? what does g means here is it a variable ? the output is z=function g at 0x15b43b0 , what does this mean?
one last thing , what does z() in the last line measn? there is no function called z !!
def f(x):
def g():
x='abc'
print 'x=',x
def h():
z=x
print 'z=',z
x=x+1
print 'x=',x
h()
g()
print 'x=',x
return g
x=3
z=f(x)
print 'x=',x
print 'z=',z
z()
freturns the value ofg, which is a function, sofreturns a function. In the main code, that function is stored inz, sozreally is a function, and can be called.