June 2017
Beginner
352 pages
8h 39m
English
Python objects show this name-binding behavior for all types. The assignment operator only ever binds object to names, it never copies an object by value. To help make this point crystal clear, let's look at another example using mutable objects: Lists. Unlike the immutable ints that we just looked at, list objects have mutable state, meaning that the value of a list object can change over time.
To illustrate this, we first create an list object with three elements, binding the list object to a reference named r:
>>> r = [2, 4, 6]>>> r[2, 4, 6]
We then assign the reference r to a new reference s:
>>> s = r>>> s[2, 4, 6]
The reference-object diagram for this situation makes it clear that we have two names referring ...
Read now
Unlock full access