Depth copy _python

A shallow copy

Copy of the first layer of something, such as a list of other modify their shared second layer (or deeper), he can stop, can only follow the change.

Use: rarely used, shared different accounts associated with:

 

Copy Import 
Husband = [ 'Chen', '123', [15000,9000]]
wife = copy.copy (Husband)
wife [0] = "Wang"
wife [. 1] = '234' # modifying the first layer, there is no change
print (husband) # [ 'chen ', '123', [15000, 9000]]
wife [2] [. 1] = 12000 # modifying the second layer will vary
print (husband) # [ 'chen ', '123', [15000, 12000]]



Second, the deep copy
fully replicated all changes do not affect
Copy Import
Husband = [ 'Chen', '123', [15000,9000]]
wife = copy.deepcopy (Husband)
wife [0] = "Wang"
wife [. 1] = '234' # modifying the first layer, there is no change
print (husband) # [ 'chen ', '123 ', [15000, 9000]]
wife [2] [. 1] = 12000 # modifying the second layer, no change in
print (husband) # [ 'chen ', '123 ', [15,000, 9000]]

Guess you like

Origin www.cnblogs.com/chenxiaozan/p/12121612.html