1.reverse列表反轉排序,無返回值
x = [1,5,2,3,4]
x.reverse()
輸出:[4, 3, 2, 5, 1]
2.sort列表排序,無返回值
正序:
a = [5,7,6,3,4,1,2]
a.sort()
輸出:[1, 2, 3, 4, 5, 6, 7]
逆序:
a.sort(
reverse
=
False
)
輸出:[7,6,5,4,3,2,1]
3.sorted列表排序,有返回值
a = [5,7,6,3,4,1,2]
b = sorted(a)
輸出:
a----[5, 7, 6, 3, 4, 1, 2]
b----[1, 2, 3, 4, 5, 6, 7]