Python List sort() Method

  • Post category:List

The sort() method sorts the list ascending by default. You can also make a function to decide the sorting criteria.

In this blog post, you will learn how to use the python list sort() method.

Step 1: Create a list

my_list = [4, 5, 2, 1, 3]

Step 2: Sort the list

my_list.sort()

Step 3: Print the list

print(my_list)

Output:

[1, 2, 3, 4, 5]