Assignment to argument names doesn't affect the caller

This is something that can be tricky to understand at first, so let's look at an example:

# key.points.assignment.py
x = 3
def func(x):
x = 7 # defining a local x, not changing the global one
func(x)
print(x) # prints: 3

In the preceding code, when the x = 7 line is executed, within the local scope of the func function, the name, x, is pointed to an integer with a value of 7, leaving the global x unaltered.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset