Skip to content

Python sort reverse order | Example code

  • by

Use sort() with reverse=True to sort a list in reverse order in Python. The sort() method sorts the list ascending by default.

Python sort reverse example

Simple example code use reverse attribute in the sort method. Set it equal to True to sort the list in reverse order in place.

a_list = [1, 2, 3]

a_list.sort(reverse=True)

print(a_list)

Output:

Python sort reverse order

Do comment if you have any doubts or suggestions on this Python sort tutorial.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Your email address will not be published. Required fields are marked *