output is not what I think it should be

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() 


Category: python Time: 2016-07-28 Views: 0
Tags: python

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development


Front-end development


development tools

Open Platform

Javascript development

.NET development

cloud computing


Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.188 (s). 12 q(s)