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