python深拷贝浅拷贝

http://blog.csdn.net/echoutopia/article/details/51725430
import copy
a = [1,2,3,4,5,[6,7,8]]
b = a[:]
c = a
d = copy.deepcopy(a)
e = copy.copy(a)
print "id of a :",id(a)
print "id of b :",id(b)
print "id of c :",id(c)
print "id of d :",id(d)
print "id of e :",id(e)
print "\n"
print "id of a['5'] :",id(a[5])
print "id of b['5'] :",id(b[5])
print "id of c['5'] :",id(c[5])
print "id of d['5'] :",id(d[5])
print "id of e['5'] :",id(e[5])



id of a : 140182194535024
id of b : 140182194565416
id of c : 140182194535024
id of d : 140182194581232
id of e : 140182194392960

id of a['5'] : 140182194947208
id of b['5'] : 140182194947208
id of c['5'] : 140182194947208
id of d['5'] : 140182194565344
id of e['5'] : 140182194947208



本人出于个人兴趣,创建了一个个人公众号,每天筛选国外网友发现的有趣的事情推送到公众号,欢迎关注!

python深拷贝浅拷贝_第1张图片


你可能感兴趣的:(python,浅拷贝,深拷贝,分片,python)