June 2017
Beginner
352 pages
8h 39m
English
Let's look at another instructive example. First, we'll create a new list f:
>>> f = [14, 23, 37]
Then we'll create new a function replace(). As the name suggests, rather than modifying its arguments replace() will change the object that its parameter refers to:
>>> def replace(g):... g = [17, 28, 45]... print("g =", g)...
We now call replace() with actual argument f:
>>> replace(f)g = [17, 28, 45]
This is much as we'd expect. But what's the value of the external reference f now?
>>> f[14, 23, 37]
The object reference f still refers to the original, unmodified list. This time, the function did not modify the object that was passed in. What's going on?
The answer is this: The object reference f was assigned ...
Read now
Unlock full access