Reverse List in Python Tutorial Example

09-Jun-2023

.

Admin

Reverse List in Python Tutorial Example

Hi Dev,

This tutorial will give you an example of how to reverse sort a Python list. step by step explain how to reverse the order of the list Python. I would like to show you how to reverse sort in a Python list. you can understand the concept of how to reverse the Python list.

There are several ways to reverse order Python lists. I will give you simple three examples to reverse sort with Python list. we will use reverse(), sort() and [::-1] to sorting descending order to python list.

Example 1:


main.py

myList = [1, 2, 3, 4]

# python list reverse order

myList.reverse()

print(myList)

Output:

[4, 3, 2, 1]

Example 2:

main.py

myList = [1, 2, 3, 4]

# python list reverse order

myList = myList[::-1]

print(myList

Output:

[4, 3, 2, 1]

Example 3:

main.py

myList = [1, 2, 3, 4]

# python list reverse order

myList.sort(reverse=True)

print(myList)

Output:

[4, 3, 2, 1]

#Python