017、a.sort(reverse=True) 与 a.reverse()
a.sort(reverse=True) : reverse 为关键字参数, 先排序再反转 ;
a.reverse() :reverse() 为方法,把a反转 ;
a = [2, 4, 1, 3] a.sort(reverse=True) print(a) b = [2, 4, 1, 3] print(b[::-1]) c = [2, 4, 1, 3] c.reverse() print(c)
执行结果如下:
D:\SkyWorkSpace\WorkSpace\Pytest\Temp\day09\venv\Scripts\python.exe D:/SkyWorkSpace/WorkSpace/Pytest/Temp/day09/test_01/test_01.py [4, 3, 2, 1] [3, 1, 4, 2] [3, 1, 4, 2] Process finished with exit code 0