import copylist1=[1,2,3,4,5]c_list1=list1c_list1[0]=-1for i in list1: print str(i)+' ',#输出的世 -1,2,3,4,5print '\n'print "+++++++++++++++++"list2=[1,2,3,4,5]c_list2=[i for i in list2] #并不是深拷贝c_list2[0]=6list2[0]=-1for 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]