Sort List
Sort a list of numbers in ascending order.
BeginnerTopic: List Programs
Python Sort List Program
This program helps you to learn the fundamental structure and syntax of Python programming.
# Program to sort a list of numbers
numbers = list(map(float, input("Enter numbers separated by space: ").split()))
numbers.sort()
print("Sorted list:", numbers)Output
Enter numbers separated by space: 3 1 4 2 Sorted list: [1.0, 2.0, 3.0, 4.0]
Understanding Sort List
We use the in-place .sort() method to sort the list in ascending order.
Note: To write and run Python programs, you need to set up the local environment on your computer. Refer to the complete article Setting up Python Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your Python programs.