locals() Is Read-Only: globals() Is Not : Local Variables « Language Basics « Python






locals() Is Read-Only: globals() Is Not

locals() Is Read-Only: globals() Is Not
def foo(arg): 
    x = 1 
    print locals()             
    locals()["x"] = 2          
    print "x=",x               

z = 7 
print "z=",z 
foo(3) 
globals()["z"] = 8             
print "z=",z                   
           
       








Related examples in the same category

1.local variable hides globallocal variable hides global