Reverse List Python | Python examples for Beginners to Advance

From this tutorial, you’ll be studying Reverse list python methodology. You will see how to apply it to sequences with the assistance of examples.

Note: The syntax used in the beneath part is for Python 3. You can change it to another variation of Python.

Reverse List Python

Here we will see the reverse() method with examples. How can we reverse the list in Python?

List Reverse Method

The Reverse methodology permits you to invert the order of an inventory of parts. You can use this methodology to change the precedence of sorting order, and so forth.

Its syntax is as follows:

List_name.reverse()

This methodology counts the variety of cases of a component in an inventory. See the beneath instance.

How does the Reverse() perform work?

This methodology doesn’t settle for any argument and additionally has no return worth. It solely creates an up-to-date checklist which is the reverse of the unique sequence.

Please do not confuse the reverse() methodology with reversed(). The latter permits accessing the checklist in the reverse order whereas the reverse performance merely transposes the order of the weather.

The flowchart beneath makes an attempt to clarify it in a diagram:

Reverse list python
Python reverse checklist

Reversing an inventory of numbers

# Initilize the checklist of numbers
Cubes = [1,8,27,64,125]
Cubes.reverse()
print (Cubes)

The consequence is as follows:

[125, 64, 27, 8, 1]

Reversing an inventory containing strings

# Initialize the checklist of strings
Mathematics = ["Number Theory", "Game Theory", "Statistics", "Set Theory"]
Mathematics.reverse()
print (Mathematics)

The consequence is as follows:

['Set Theory', 'Statistics', 'Game Theory', 'Number Theory']

Reversing an empty checklist

# Initialize an empty checklist
List = []
List.reverse()
print (List)

The consequence is as follows:

[]

###Python Tutorial###

Reverse list python, For more Search in Wikpedia

Pramod Kumar Yadav is from Janakpur Dham, Nepal. He was born on December 23, 1994, and has one elder brother and two elder sisters. He completed his education at various schools and colleges in Nepal and completed a degree in Computer Science Engineering from MITS in Andhra Pradesh, India. Pramod has worked as the owner of RC Educational Foundation Pvt Ltd, a teacher, and an Educational Consultant, and is currently working as an Engineer and Digital Marketer.