赞
踩
总结:
1、copy.copy 浅拷贝 只拷贝父对象,不会拷贝对象的内部的子对象
2、copy.deepcopy 深拷贝 拷贝对象及其子对象
1、对象赋值
will = ["Will", 28, ["Python", "C#", "JavaScript"]]
wilber = will #对象赋值(对象引用)
print id(will)
print will
print [id(ele) for ele in will]
print id(wilber)
print wilber
print [id(ele) for ele in wilber]
will[0] = "Wilber"
will[2].append("CSS")
print id(will)
print will
print [id(ele) for ele in will]
print id(wilber)
print wilber
print [id(ele) for ele in wilber]
结果:
下面来分析一下这段代码:
(1)首先,创建了一个名为will的变量,这个变量指向一个list对象,从第一张图中
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。