引用:指针指向同一个对象
浅拷贝:只拷贝父对象,子对象的内容依旧是引用
深拷贝:完全拷贝
代码:
import copy
a = [1,2,3,[4,5]]
b = a
c = copy.copy(a)
d = copy.deepcopy(a)
a.append(6)
a[3].append(7)
print "a",a
print "b",b #因为是引用,和a完全一致
print "c",c #父对象完全拷贝,所以a怎么改父对象没影响,子对象[4,5]是引用,所以指向了[4,5,7]
print "d",d #完全没影响
结果:
>>>
a [1, 2, 3, [4, 5, 7], 6]
b [1, 2, 3, [4, 5, 7], 6]
c [1, 2, 3, [4, 5, 7]]
d [1, 2, 3, [4, 5]]
>>>