【python】分片copy和等号的区别
例一
>>> list1=[1,2,3,4]
>>> list2=list1
>>> list3=list1[:]
>>> list1.reverse()
>>> print(list1)
[4, 3, 2, 1]
>>> print(list2)
[4, 3, 2, 1]
>>> print(list3)
[1, 2, 3, 4]
例2
old = [1, 2, 3, 4, 5]
new1 = old
old.reverse()
old = [1,2,2]
print(new1)
结果
[5, 4, 3, 2, 1]
在第二例子中,old= [1,2,2],将old变量贴到[1,2,2]上