Python 数组截取
# 数据源
names = ['a', 'b', 'c', 'd', 'e', 'f']
# 正常获取
print(names[1]) # b
# 截取
print(names[0:3]) # ['a', 'b', 'c']
print(names[3:10]) # ['d', 'e', 'f']
# 截取:从指定开始直接到指定结尾
print(names[3:]) # ['d', 'e', 'f']
print(names[:3]) # ['a', 'b', 'c']
# 倒着切
print(names[-2: -1]) # ['e']
print(names[-2:]) # ['e', 'f']
# 跳着切,步长
print(names[0: 5: 2]) # ['a', 'c', 'e']
print(names[0::2]) # ['a', 'c', 'e']
print(names[::2]) # ['a', 'c', 'e']