list:[::5]
0-99的数列
L = [0, 1, 2, 3, ..., 99]
所有数,每5个取一个
>>> L[::5]
[0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95]
甚至什么都不写,只写[:]
就可以原样复制一个list:
>>> L[:]
[0, 1, 2, 3, ..., 99]
前10个数,每两个取一个:
>>> L[:10:2]
[0, 2, 4, 6, 8]
--------------------------------------------------------------------------------------------
例二:
L1 = [1, 2, 3, 4, 5,6]
取L1的偶数位元素组成新的list
b = L1[1::2]
输出
[2, 4, 6]