Python Sort Numbers: Ascending Order Guide
You can use the sorted() function to sort a list of numbers as shown below:
numbers = [5, 2, 8, 1, 9]
sorted_numbers = sorted(numbers)
print(sorted_numbers)
Output:
[1, 2, 5, 8, 9]
Alternatively, you can use the sort() method of a list, as shown below:
numbers = [5, 2, 8, 1, 9]
numbers.sort()
print(numbers)
Output:
[1, 2, 5, 8, 9]