Follow this blog by Email

Wednesday, 7 August 2013

Puzzle about Life and Scope of Local and Global variables in Python programming language

Here is a puzzle about python language, local and global variables and the point where and when they are defined initialized.

What do you think would be the output of this simple python code snippet
Will post the answer and its explanation in a while.

i=333  
 def test():  
   print "Global i =", i  
   for i in range(10):  
     print "Local i = ",i  
 test() 

No comments: