Python list sort

In this article, you’ll see how to sort a list in Python. The sort method is used to sort the elements in ascending or descending order. I highly recommend you get the “Python Crash Course Book” to learn Python.

Sort the list in ascending order

If you want to sort a list in increasing order then don’t specify any argument in the sort method.

Python

Output:

[10, 20, 35, 40, 55]

Sort in descending order

If you want to sort a list in decreasing order then specify the (reverse=True) argument in the sort method.

Python

Output:

[55, 40, 35, 20, 10]

Leave a Comment

Your email address will not be published.