this is my first question on the site, I highly appreciate any feedback, the book I'm working on by Guttag from MIT says that the program would print the following:enter code here
x=4 z=4 x = abc x=4 x=3 z = <function g at 0x15b43b0> x = abc
my question is, why does the first x displayed have a value of 4, it is binded to 3, and is printed before the function is called, and is in the main name space, not local to function. Please, if anyone can explain to me why the output printed is what it is, it would be of great help, thanks in advance.
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()