[::1] [::2]

python中这个两个是切片的一种操作。

[::1]是一个一取 [::2]是两个一取

a = [1, 2, 3, 4]
b = [[1,2,3], [4,5,6], [7,8,9], [10,11,12]]

if __name__ == '__main__':
    print(a[::1])
    print(a[::2])
    print(a[::3])
    print(b[::1])
    print(b[::2])

答案:

[1, 2, 3, 4]
[1, 3]
[1, 4]
[[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]
[[1, 2, 3], [7, 8, 9]]
文章目录