Python List sort() Method

Last Updated : 5 Jan 2026

The Python list sort() method is an inbuilt method that allows the user to sort the elements of the list either in ascending or descending order. This function doesn't return any value because no new list is created instead, it modifies the list and replaces it with the current one. The sort() function is a useful method as it helps the developers to arrange the list in numeric or alphabetical order.

Syntax of the sort() Method in Python List

The following is the syntax of the list sort() method:

Parameter

  • key (Optional):This parameter allows the user to specify a function to be used for sorting criteria. For example, if you want to sort the list on the basis of its length you can simple use the len() function.
  • reverse (Optional):Its takes Boolean If you set the reverse argument to Boolean True, the list would be sorted in descending order, else it would sort the list in ascending order. By default, it is set to False.

Return

The sort() method in Python returns none.

Examples of List sort()

We will now take a look at some examples of the list sort() method in Python.

Example 1: Sort List in Ascending Order

In the following example, we will understand the working of the sort() method to sort a given list in ascending order.

Example

Execute Now

Output:

[0, 1, 5, 7, 10, 14]

Explanation:

In the above example, we have sorted the given list in ascending order using the sort() method.

Example 2: Sort List in Descending Order

We can sort the given list in descending order by setting the reverse argument of the sort() method to True, as shown in the following example:

Example

Execute Now

Output:

[14, 10, 7, 5, 1, 0]

Explanation:

In this example, we have reversed the order of the sorted list by setting the reverse parameter to True.

Example 3: Sort a List in order of the Length of the Values

We will create a function and sort the given list in order of the length of the values as shown in following example:

Example

Execute Now

Output:

['Apple', 'Melon', 'Orange', 'Strawberry']

Explanation:

Here, we have used the key parameter in sort() method and set it to the function, we defined. This function returns the length of each element present in the list and sort them accordingly in ascending order.

Things to Remember

  1. The Python sort() method is used to modify the list in place.
  2. The Python sort() method returns None.
  3. By default, the sort() function sorts the list in ascending order. You can also sort the list in descending order, all you need to do is to set the reverse parament to true.
  4. The key parameter can be used for customizing the sorting criteria.
  5. We can use the sort() method, if we need to create a new sorted list without changing the original list.
  6. By default, the sort() method is case sensitive. It means all the capital letters will be sorted before.

Conclusion

Python contains different built-in methods and functions that help developers to easily create flawless software. The Python list sort() method is extremely useful in situations where you want to quickly sort the list alphabetically, numerically, whether in ascending order or descending order. This tutorial has covered all the details and examples regarding this method, but don't limit yourself to these examples; instead, try more and more examples to be proficient.