import copy
list1=[1,2,3,4,5]
c_list1=list1
c_list1[0]=-1
for i in list1:
print str(i)+' ',
#输出的世 -1,2,3,4,5
print '\n'
print "+++++++++++++++++"
list2=[1,2,3,4,5]
c_list2=[i for i in list2] #并不是深拷贝
c_list2[0]=6
list2[0]=-1
for i in list2:
print str(i)+' ',
print '\n'
for i in c_list2:
print str(i)+' ',
#输出-1,2,3,4,5
#输出6,2,3,4,5,
print '\n'
print "+++++++++++++++++"
list3=[1,2,3,4,[5,6,7,8]]
c_list3=[i for i in list3]#for是将list3中的每一个对象的引用拷贝
c_list3[4].append(9) #这样就会出问题
for i in list3:
print i,
#输出1,2,3,4,[5,6,7,8,9]
print '\n'
#深拷贝
list4=[1,2,3,4,[5,6,7,8]]
c_list4=copy.deepcopy(list4)
c_list4[4].append(9)
for i in list4:
print i,
#输出1,2,3,4,[5,6,7,8]