December 2000
Intermediate to advanced
816 pages
16h 57m
English
Earlier in Section 3.5, we described how object assignments are simply object references. This means that when you create an object, then assign that object to another variable, Python does not copy the object. Instead, it copies only a reference to the object. For example:
>>> aList = [[78, 'pyramid'], [84, 'vulture'], [81, 'eye']] >>> anotherList = aList >>> aList [[78, 'pyramid'], [84, 'vulture'], [81, 'eye']] >>> >>> anotherList [[78, 'pyramid'], [84, 'vulture'], [81, 'eye']]
Above, a list of two elements is created and its reference assigned to aList. When aList is assigned to anotherList, the contents of the list reference by aList are not copied when anotherList is created. Rather, anotherList “copies” ...
Read now
Unlock full access