a=[1,2,3,4,5]
b=a
针对复杂数据类型(字符串和数字除外):a和b指向同一块内存空间,其中任一个发生改变,另外一个也会改变
浅拷贝只拷贝一层:
husband = ['xiaohua',123,[10000,6000]]
wife = husband.copy()
wife[0] = 'xiaopang'
wife[1] = 345
husband[2][1] -= 1500
print(wife)
深拷贝:克隆一份
import copy
husband = ['xiaohua',123,[10000,6000]]
wife = copy.copy(husband) #浅拷贝
xiaosan = copy.deepcopy(husband)
xiaosan[0] = 'jinxin'
xiaosan[1] = 666
xiaosan[2][1] -= 1000
husband[2][1] -= 1500
print(wife)
print(xiaosan)
来源:https://www.cnblogs.com/benchdog/p/9053437.html