Python中的切片
name = [1,2,3,4,5,6,7] print(name[:]) 取整个列表 [1, 2, 3, 4, 5, 6, 7] print(name[:2]) 取前面两个 [1, 2] print(name[-4:]) 从倒数第四个开始取 [4, 5, 6, 7] print(name[::2]) 每2个取一个 [1, 3, 5, 7] print(name[2:4]) 从第三个取到第五个 [3, 4]
name = [1,2,3,4,5,6,7] print(name[:]) 取整个列表 [1, 2, 3, 4, 5, 6, 7] print(name[:2]) 取前面两个 [1, 2] print(name[-4:]) 从倒数第四个开始取 [4, 5, 6, 7] print(name[::2]) 每2个取一个 [1, 3, 5, 7] print(name[2:4]) 从第三个取到第五个 [3, 4]