你可以使用sorted()函數(shù)對數(shù)字列表進(jìn)行排序,如下所示:
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]