Sort List in Python

Sort a list of numbers in ascending order.

BeginnerList ProgramsExample 9 of 25
sort-list.py
Run in browser
1# Program to sort a list of numbers
2
3numbers = list(map(float, input("Enter numbers separated by space: ").split()))
4
5numbers.sort()
6
7print("Sorted list:", numbers)

Output

Enter numbers separated by space: 3 1 4 2
Sorted list: [1.0, 2.0, 3.0, 4.0]

What's going on

We use the in-place .sort() method to sort the list in ascending order.