How to Reverse a List in Python?

By Hardik Savani October 30, 2023 Category : Python

Hello Friends,

This post is focused on how to reverse sort python list. Here you will learn how to reverse order of list python. you will learn how to reverse sort in python list. we will help you to give an example of how to reverse python list.

There are several ways to reverse order python list. i will give you simple three example 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, 5]
  
# python list reverse order
myList.reverse()
  
print(myList)

Output:

[5, 4, 3, 2, 1]

Example 2:

main.py

myList = [1, 2, 3, 4, 5]
  
# python list reverse order
myList = myList[::-1]
  
print(myList)

Output:

[5, 4, 3, 2, 1]

Example 3:

main.py

myList = [1, 2, 3, 4, 5]
  
# python list reverse order
myList.sort(reverse=True)
  
print(myList)

Output:

[5, 4, 3, 2, 1]

I hope it can help you...

Tags :
Shares