Main.LocalVariables History
Hide minor edits - Show changes to markup
January 28, 2010, at 03:01 PM MST
by -
Added lines 1-33:
(:source lang=python:)
"""Local variables"""
- When you create a local variable inside a function, it only exists
- inside the function, and you cannot use it outside.
- also, modifying a parameter does not affect the variable that
- was passed into the function
- for example:
def test_locality(var1, var2) :
print "in the method 'test_locality'"
print "var1", var1, "var2", var2
print "after modifying the variables"
var1 = 100
var2 = 'python'
print "var1", var1, "var2", var2
var1 = 1 var2 = "a string" print "var1", var1, "var2", var2 test_locality(var1, var2) print "back in main" print "var1", var1, "var2", var2
- although the variables have the same name, they are different
- instances
(:sourceend:)
