The list is sorted python

Sorting list

A=[1,15,4,6,8,5,45,2]
A.sort()    # 都是数值才能用,否则报错
print(A)    # 结果为:[1, 2, 4, 5, 6, 8, 15, 45]
A.reverse() # 逆序
print(A)    # 结果为:[45, 15, 8, 6, 5, 4, 2, 1]

Here Insert Picture Description
Reverse inner key function

A=[1,2,3,4,"a","b"]
A.reverse() # 逆序后列表A 已经被修改了
print(A)    

Here Insert Picture Description
Slicing method utilizing reverse order

A=[1,2,3,4,"a","b"]
print(A[::-1])	 # 列表A并没有被修改

Here Insert Picture Description

Guess you like

Origin blog.csdn.net/GrofChen/article/details/91466264