June 2017
Beginner
352 pages
8h 39m
English
Indeed, the full slice is an important idiom for copying a list. Recall that assigning references never copies an object, but rather merely copies a reference to an object:
>>> t = s>>> t is sTrue
We deploy the full slice to perform a copy into a new list:
>>> r = s[:]
And confirm that the list obtained with the full slice has a distinct identity:
>>> r is sFalse
Although it has an equivalent value:
>>> r == sTrue
It's important to understand that although we have a new list object which can be independently modified, the elements within it are references to the same objects referred to by the original list. In the event that these objects are both mutable and modified (as opposed to replaced) the change will be seen in both ...
Read now
Unlock full access