- 語法:列表名[start:stop:step]
- a = [1,2,3,4,5,6]
- print('無設(shè)置默認(rèn)輸出:',a)
- print('切片下標(biāo)為0-1:',a[0:2:])#結(jié)果為[1, 2]
- print('切片下標(biāo)為0-5,步長為2:',a[0:5:2])#結(jié)果為[1, 3, 5]
- a = [1,2,3,4,5,6]
- print('無設(shè)置默認(rèn)輸出:',a)
- print('步長為1:',a[::1])
- print('步長為2:',a[::2])
- print('步長為負(fù)數(shù)是倒序排序:',a[::-1])