浅拷贝、深拷贝和正常作业到底有什么区别?import copy
a=”deepak”b=1,2,3,4c=[1,2,3,4]d={1:10,2:20,3:30}a1=copy.copy(a)b1=copy.copy(b)c1=copy.copy(c)d1=copy.copy(d)print "immutable - id(a)==id(a1)"
,id(a)==id(a1)print "immutable - id(b)==id(b1)",id(b)==id(b1)print "mutable - id(c)==id(c1)",id(c)==id(c1)print "mutable
- id(d)==id(d1)",id(d)==id(d1)我得到以下结果-immutable - id(a)==id(a1) Trueimmutable - id(b)==id(b1) Truemutable - id(c)==id(c1) Falsemutable - id(d)==id(d1) False如果我做深度复制-a1=copy.deepcopy(a)b1=copy.deepcopy(b)c1=copy.deepcopy(c)d1=copy.deepcopy(d)结果是一样的-immutable - id(a)==id(a1) Trueimmutable - id(b)==id(b1) Truemutable - id(c)==id(c1) Falsemutable - id(d)==id(d1) False如果我从事外派工作-a1=a
b1=b
c1=c
d1=d结果是-immutable - id(a)==id(a1) Trueimmutable - id(b)==id(b1) Truemutable - id(c)==id(c1) Truemutable - id(d)==id(d1) True有人能解释一下到底是什么让拷贝之间有区别吗?它与可变和不变的对象有关吗?如果是的话,你能给我解释一下吗?
3 回答
慕沐林林
TA贡献2016条经验 获得超9个赞
copies
添加回答
举报
0/150
提交
取消