python怎么将数字从小到大排列

你可以使用sorted()函数对数字列表进行排序,如下所示:

numbers = [5, 2, 8, 1, 9]
sorted_numbers = sorted(numbers)
print(sorted_numbers)

输出:

[1, 2, 5, 8, 9]

或者你可以使用列表的sort()方法,如下所示:

numbers = [5, 2, 8, 1, 9]
numbers.sort()
print(numbers)

输出:

[1, 2, 5, 8, 9]
阅读剩余
THE END