×

Python List reverse() method

 Python List reverse() method

The list.reverse () method in Python reverses the elements of the list in place.

Syntax

list.reverse()

Parameter

NA

Example 1

# Python program explaining
# the list.reverse() method
weekList = ['Sun','Thurs','Mon','Fri', 'Tues', 'Wed']
print("Actual week list: ",weekList)
# Reversing the week list by calling the reverse() method 
weekList.reverse()
# printing the reverse week list
print("Reversed week list:",weekList) 

Output

Actual week list:  ['Sun', 'Thurs', 'Mon', 'Fri', 'Tues', 'Wed']
 Reversed week list: ['Wed', 'Tues', 'Fri', 'Mon', 'Thurs', 'Sun'] 

Example 2

# Python program explaining
# the list.reverse () method
# passing the number list
num = [11, 13, 14, 12,15] 
print("Actual List: ",num)
# Sorting list of Integers in descending 
num.sort(reverse = True)  
# printing the reverse order 
print("Reverse List: ",num) 

Output

Actual List:  [11, 13, 14, 12, 15]
Reverse List:  [15, 14, 13, 12, 11] 

Example 3

# Python program explaining
# the list.reverse() method
# passing the number List
numList = [1,2,3,4,5,6,7,8,9,10,12]
print("Actual List: ",numList) 
# Reversing the Order of the elements
# Syntax: reversed_list = os[start:stop:step]  
reversed_list = numList[::-1]
# printing the list
print('Updated List:', reversed_list) 

Output

Actual List:  [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12]
Updated List: [12, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1] 


Related Topics

Python Boolean

In this article, you will learn the boolean variables in python, bool() function in python, and bool operators with examples, Boolean Objects in Python. There are the only two possible values...

6 minutes read.

Python Set intersection_update() method

Python Set intersection_update() method The set.intersection_update() method in Python removes the items that is not present in both sets. It is different from the set.intersection() method, because the intersection()method returns a new set, with only  the common elements...

2 minutes read.

Iterators in Python

Introduction In Python, an iterator is defined as an object that enables traversing through all the values of a collection. It contains the countable number of values. The iterator is utilized to...

4 minutes read.

Yield Statement In Python

The generators are defined by using the yield statement in Python. Generally, it converts a normal Python function into a generator.  The yield statement hauls the function and returns back the...

2 minutes read.

Insertion Sort using Python

Insertion sort is a type of sorting technique that is used for sorting an array with random elements. Using sorting methods, any unsorted array can be sorted into ascending or...

3 minutes read.

Python sort() function

Python provides many built-in functions for solving many problems that arise in different situations in programs. One of such methods is the sort () method. In this article, the syntax...

4 minutes read.

Python int()

Python int() class The int() class in Python returns an integer object constructed from a number or string x. Syntax class int(x, base=10) Parameter x: This parameter represents a number or a string that can be converted into...

1 minute read.

Python Modulo

For basic calculations, Python provides operators. Python supports a broad range of Arithmetic Operators to do arithmetic, as given below: +Addition*Multiplication-Subtraction/Division//Floor division**Exponentiation%Remainder/Modulus As you can see, one of these basic arithmetic operators...

8 minutes read.

Tuple in Python

Tuples Tuples are the same as the list but as we know that lists are mutable means we can change the data from it. In the tuple we cannot change the...

6 minutes read.

Python | a += b is not always a = a + b

a += b in Python doesn't always behave the same way as a = a + b; the same operands can produce different outcomes depending on the circumstances. But we...

3 minutes read.

Algorithm for Factorial of a number in Python

What is a Factorial Number? In mathematics, the factorial of a positive integer n, denoted by n!. It is the product of all positive integers less than or equal to n. For...

3 minutes read.

How to check version of Python

How to check version of python The versions of Python come with different kinds of features and functionalities. It is not a herculean task to keep track of the updates these...

3 minutes read.

Convert List to Array in Python

What is List in Python? In Python, a list is a built-in data structure that stores a collection of items. The items in a list can be of any data type,...

3 minutes read.

Genetic Algorithm in python

Python : Python is an object oriented programming language which is highly interpreted and is highly interactive. Python was created by Guido van Rossum in the year 1985 – 1990 .The source...

4 minutes read.

How to build a Virtual Assistant Using Python

What is a virtual assistant? A virtual assistant is a new and very interesting concept in today’s world. When we hear the word “Virtual Assistant”, we can easily visualize “Jarvis or...

8 minutes read.

Python Lists vs Tuples

The difference between lists and tuples is one of the most frequently asked questions in an interview related to python language. Lists and Tuples are two of Python’s built-in data...

4 minutes read.

How to create a dictionary in Python?

How to create a dictionary in python Dictionary is a data structure in Python that represents our data in the form of keys and values. Each value in a dictionary can be...

5 minutes read.

Adding item to a python dictionary

The dictionary is one of python’s built-in data structures where it stores key-value pairs. A dictionary is a collection of ordered values that can be changeable. We can add, modify,...

3 minutes read.

After Python, What Should I Learn

Python is a programming language used to create websites, software, and other projects. It is easy to code and easy to learn. After learning Python, there are many different directions...

4 minutes read.

Python Time Module

Python contains many files that can be imported into a python code and used whenever we want. One of that modules is the time module. It is a good practice...

6 minutes read.