Home >Backend Development >Python Tutorial >Python Program: How to Sort a List of Numbers
A list is a collection of items in python, created using square brackets [] . List can contain different data types, including numbers, strings and other lists. List is mutable ( It can't changed/modified).
In list very easily numbers can be sorted.
Before starting sort the list, you need to know about List & How to create a list.
In the beginning, We will create a list
# Create a list with Numbers my_list = [10,80,20,60,30,40,70] # Print the list print("List: ", my_list)
Here, 10, 80, 20, 60, 30, 40 and 70 are Numbers or we can call integer type data.
We will store these numbers in my_list variable.
print() is a builtin function in python which used to print or show the result whatever we want.
sorted() is used for sort a list in ascending order & can be descending order by setting the reverse parameter to True.
The above is the detailed content of Python Program: How to Sort a List of Numbers. For more information, please follow other related articles on the PHP Chinese website!