Import Copy
#浅拷贝
person = ["Name", ["Saving", 1000]]
P1 = copy.copy (person)
P2 = person.copy () #两种都是浅拷贝
Print (PERSON,P1,P2)
# # #结果为 [' name ', [' saving ', [+]] [' Name ', [' saving ', ' +]] [' Name ', [' saving ', 1000]]
Person[0] = "Clark"
Print (PERSON,P1,P2)
# # #结果为 [' Clark ', [' saving ', +]] [' Name ', [' saving ', ' + '] [' name ', [' saving ', ' + ']] single character unchanged
PERSON[1][1] = 2000
Print (PERSON,P1,P2) #记住这两种方式的最后结果
# # # #结果为 [' Clark ', [' saving ', ' +]] [' Name ', [' saving ', ' +]] [' Name ', [' Saving ', ']] ' list value changed, corresponding to the list value in the light copy corresponding change
P1[0] = "Xu Hongbiao"
Print (PERSON,P1,P2)
# #结果为 [' Clark ', [' Saving ', 2000]] [' Xu Hongbiao ', [' Saving ', ' [']] [' Name ', [' Saving ', 2000]]
P1[1][1] = 3000
Print (PERSON,P1,P2)
# #结果为 [' Clark ', [' Saving ', 3000]] [' Xu Hongbiao ', [' saving ', ' +]] [' Name ', [' saving ', ' +]] conclusion Ibid .
#深拷贝
Info = ["Name", ["Love", 20]]
Info1 = copy.deepcopy (info)
Info2 = copy.deepcopy (info)
Print (Info,info1,info2)
Info[0] = "Clark"
Print (Info,info1,info2)
INFO[1][1] = 30
Print (Info,info1,info2)
INFO1[1][1] = 40
Print (Info,info1,info2) #深拷贝, each independent so no matter how you modify any one, the other June unchanged
A brief analysis of Python's shades of Copy