Tag: Print priority also port EPC depth copy style list memory
One: Shallow copy
= [123, [456= copy.copy (L1) l2[3] [03 # Modify elements of Level two list l2[11print (L1) print (L2)
Results:
[1, 2, 3, [3, 5, 6]]
[1, 1, 3, [3, 5, 6]]
Level Two list will change with either side of the changes, L1 of the level two list if the priority change then L2 two level list will also change, similarly, L2 priority change is the same
In addition, the data of a level list is independent, it will re-open a piece of memory space and copy the data elements of the first level list, the level two list is simply a reference and will not copy
Two: Deep copy
= [123, [456= copy.deepcopy (L1) l2[3 [03 # Modify elements of Level two list l2[11print (L1) print (L2)
#结果:
[1, 2, 3, [4, 5, 6]]
[1, 1, 3, [3, 5, 6]]
Deep Copy is a re-opening of the memory space and a complete copy of the data, L1 and L2 do not affect each other
Python depth copy