17. shades copy

copy function, list, set, dict have this function 
list
dictionary
collection
example:
S = { "name": "caona",
"Hobby": { "Paly": "Music"}
}

S1 = S
# assignment, then s s1 and the same data is shared. Another one of the modifications will be modified, since the common memory address and value
s2 = s.copy ()
# shallow copy, copy only the first layer
# copy a new data, then the first data layer and s is s2 two different data, a modification of the first layer, the first layer of the other does not change, if the modification of the second data layer, or the same data
Import Copy
S3 = copy.deepcopy (S)
# deep copy. whichever modifying layer are two independent data, if it comes to clone full two separate data

Guess you like

Origin www.cnblogs.com/xh716/p/11565106.html