×

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 Support

Python Python is an interactive and more accessible language than any other programming language. The python programming language uses a variety of libraries to perform the operations in a faster way....

3 minutes read.

Python Logical Operators

In python, there are many operators which we use in our program. Operators are used in manipulating a particular value or operand. Logical operators are used mainly to evaluate an...

7 minutes read.

Python md5() function

Python md5() function The md5() function in PHP calculates the md5 hash of a string. Syntax md5 ( string $str [, bool $raw_output] ) Parameter str(required)- This parameter specifies the string. raw_output(optional)- This parameter specifies a hex or binary output format: TRUE - Raw 16 character binary...

1 minute read.

Difference between Mutable and Immutable Objects

Difference between Mutable and Immutable Objects As we all know that Python is an object-oriented programming language. Object-oriented programming approach is based on the objects and the classes’ stores the data...

4 minutes read.

Python Queue

Python Queue There are various day to day activities where we find ourselves engaged with queues. Whether it is waiting in toll tax lane or standing on the billing counter for...

7 minutes read.

Write Dictionary to CSV in Python

Python is an Object-Oriented high-level language. Python has an English-like syntax, which is very easy to read and write codes. Python is an interpreted language which means that it uses...

4 minutes read.

NSE Tools In Python

About NSE NSE (National Stock Exchange) of India Limited is the advanced stock exchange of India. It is located in Mumbai, Maharastra and It was organized in 1992. It was...

2 minutes read.

ER diagram of the Bank Management System in python

What is an ER diagram? The full form of the ER diagram is the Entity Relationship diagram. This diagram is used in database management systems to have a rough idea of...

3 minutes read.

Map Syntax in Python

Introduction: In Python, a function called map acts as an iterator, returning a result after each item in an iterable has been subjected to a function (tuple, lists, etc.). When you...

6 minutes read.

Python Combination

Python Combination Permutations and combinations are the important part of our mathematical tools. We use them often in our Python programs. In this tutorial, we will learn about combinations in Python...

6 minutes read.

Io stringio Python

Python programming language: Python is an interactive and more accessible language than any other programming language. The python programming language uses a variety of libraries to perform the operations in a...

7 minutes read.

Python Logging Maxbytes

Python: Python is an interactive and more accessible language than any other programming language. The python programming language uses a variety of libraries to perform the operations in a faster way....

6 minutes read.

XXhash Python

Python: Python programming language is one of the most used programming languages, as it is used widely in the field of software and data analysis, web development, etc. It is said...

6 minutes read.

Python bin() function

Python bin() function The bin() function in Python returns the binary version for the specified integer. Syntax bin(x) Parameter n: This parameter represents an integer or int value. Return This function returns a binary string for the specified integer...

1 minute read.

Python Dictionary clear() method

Python Dictionary clear() method The dictionary.clear() method in Python removes all the elements from a dictionary. Syntax dictionary.clear() Parameter NA Return None Example 1 # Python program explaining # the dictionary.clear() method # initialising the dictionary fruits =...

1 minute read.

Python Key Error

What is an Error? Errors are nothing but problems in the program which occur in a program code, and this will stop the execution of the program. It is also called...

6 minutes read.

Python program to find whether a given number is even or odd

Python program to find whether a given number is even or odd A number is said to be even if any number is completely divisible by 2, which means there is...

1 minute read.

Math Module in Python

In this article, you are going to learn everything in detail about the “ math “ module in Python. We can normally work with general operations using python without importing or...

16 minutes read.

Writing to Excel using Python

Python is an Object-Oriented high-level language. Python has an English-like syntax, which is very easy to read and write codes. Python is an interpreted language which means that it uses...

3 minutes read.

Python TypeError

What is TypeError in python? TypeError is one of the exceptions in the python programming language. This exception occurs when an operation is performed on an unsupported object type or can...

6 minutes read.