[m : ] 代表列表中的第m+1项到最后一项
[ : n] 代表列表中的第一项到第n项
m = 3
n = 6
aa = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
a = aa[m : ]
b = aa[ : n]
c = aa[m : n]
print(a)
print(b)
print(c)
[3, 4, 5, 6, 7, 8, 9]
[0, 1, 2, 3, 4, 5]
[3, 4, 5]
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
双冒号的情况
list[start:end:step]
start:起始位置
end:结束位置
step:步长
- 1
- 2
- 3
- 4
- 5
- 6
- 7
>>> range(100)[20:30:2]
[20, 22, 24, 26, 28]
- 1
- 2
a=[1,2,3,4,"a","ad",45,56]
print(a[::2])#[1, 3, 'a', 45]