str,list,tuple 序列类型支持切片
# 基本切片
a = (1, 2, 3, 4, 5)
print(a[:3]) # (1, 2, 3)
print(a[1:3]) # (2, 3)
print(a[1:]) # (2,3,4,5)
print(a[:-2]) # (1,2,3)
# 切片间隔取值 a[start:stop:step]
print(a[::2]) # (1,3,5)
print(a[::-1]) # (5,4,3,2,1) 等同于tuple(reversed(a))
# 切片对象
ONE = slice(0, 1)
print(a[ONE]) # (1,)
# 多维切片
# c = ((1,2,3,4,5), (6,7,8,9,10), (11,12,13,14,15))
# print(a[1:2, 2:4])
# 切片赋值和删除
c = [1, 2, 3, 4, 5]
c[1:3] = (6, 7)
print(c) # [1,6,7,4,5]
del c[1:3]
print(c) # [1,4,5]