Dr. Xiao-Le Deng

Python 列表反转

2020-11-07 17:50
#Python

1. 具体命令

分片[::-1]

a = [1, 2, 3, 4, 5, 6, 7, 8, 9]
b = a[::-1] 
print(b)  

reversed()

a =[1, 2, 3, 4, 5, 6]
c = list(reversed(a))
print(a)

2. 参考