2-7
#列表的copy方法
names = ['a', 'b', 'c', 'd', 'e']
names2 = names.copy()
print(names)
print(names2)
names[2] = 'CC'
print(names)
print(names2)
#浅copy
names = ['a', 'b', [1, 2, 3], 'd']
names2 = names.copy()
names[1] = 'BB'
names[2][1] = 22
print(names)
print(names2)
#直接copy
names = ['a', 'b', [1, 2, 3], 'd']
names2 = names
names[1] = 'BB'
names[2][1] = 22
print(names)
print(names2)
#完全copy一份列表
import copy
#浅copy, =names.copy()
names = ['a', 'b', [1, 2, 3], 'd']
names2 = copy.copy(names)
names[1] = 'BB'
names[2][1] = 22
print(names)
print(names2)
#深copy
names = ['a', 'b', [1, 2, 3], 'd']
names2 = copy.deepcopy(names)
names[1] = 'BB'
names[2][1] = 22
print(names)
print(names2)
#列表循环
for i in names:
print(i)
#切片步长
names = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
print(names)
print(names[0:-1:2])
print(names[::2])