Variable Scope and Namespaces : Variable Scope « Function « Python Tutorial






j, k = 1, 2

def proc1():
    j, k = 3, 4
    print "j == %d and k == %d" % (j, k)
    k = 5

def proc2():
     j = 6
     proc1()
     print "j == %d and k == %d" % (j, k)


k = 7
proc1()
print "j == %d and k == %d" % (j, k)

j = 8
proc2()
print "j == %d and k == %d" % (j, k)








10.4.Variable Scope
10.4.1.Variable Scope and Namespaces
10.4.2.Shadow variable
10.4.3.globals() and locals()
10.4.4.create an instance to use the class simply as a namespace container
10.4.5.Variable name lookup in nested function
10.4.6.Local Names Are Detected Statically
10.4.7.Variable Scope in Functions