随手记——python的排序函数
python有两个常用的排序函数,一个是sort(),另一个是sorted()。
# sort()是成员函数,直接改变列表
a = [3, 1, 2]
a.sort()
print(a)
# sorted()是python的内置函数,接受一个可迭代的对象,返回一个排序好的对象,不会改变原来的列表
a1 = [3, 1, 2]
a2 = sorted(a1)
print(a1)
print(a2)
sorted()函数的用法:https://www.runoob.com/python3/python3-func-sorted.html
sort()函数的用法:https://www.runoob.com/python3/python3-att-list-sort.html

浙公网安备 33010602011771号