python索引、切片

通常一个切片操作要提供三个参数 [start_index:  stop_index:  step] 

alist = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

print(alist)
print(alist[-1: -5: -1])
print(alist[1: 5: 1])

#反转
print(alist [::-1])

#output
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
[9, 8, 7, 6]
[1, 2, 3, 4]
[9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
原文地址:https://www.cnblogs.com/onenoteone/p/12441770.html