
def func(x):
print 'x is', x
x = 2
print 'Changed local x to', x
x = 50
func(x)
print 'x is still', x
$ python func_local.py x is 50
Changed local x to 2 x is still 50
Next, we assign the value2 tox. The namex is local to our function. So, when we change the value of x in the function, thex defined in the main block remains unaffected.
In the lastprint statement, we confirm that the value ofx in the main block is actually unaffected.
Describe what you're looking for in as much detail as you'd like.
Our AI reads your request and finds the best matching books for you.
Popular searches:
Join 2 million readers and get unlimited free ebooks