Python List Reverse() - Programiz
Maybe your like
Become a certified Python programmer.
ENROLLPopular Tutorials
Getting Started With Python Python if Statement while Loop in Python Python Lists Dictionaries in Python Start Learning PythonPopular Examples
Add two numbers Check prime number Find the factorial of a number Print the Fibonacci sequence Check leap year Explore Python ExamplesReference Materials
Built-in Functions List Methods Dictionary Methods String Methods View allCreated with over a decade of experience.
- Learn
- Practice
- Compete
Certification Courses
Created with over a decade of experience and thousands of feedback.
Learn Python Learn HTML Learn JavaScript Learn SQL Learn DSA View all Courses onBecome a certified Python programmer.
Try Programiz PRO!Popular Tutorials
Getting Started With Python Python if Statement while Loop in Python Python Lists Dictionaries in Python Start Learning Python All Python TutorialsReference Materials
Built-in Functions List Methods Dictionary Methods String Methods View all Python JavaScript C C++ Java R KotlinBecome a certified Python programmer.
Try Programiz PRO!Popular Examples
Add two numbers Check prime number Find the factorial of a number Print the Fibonacci sequence Check leap year All Python ExamplesPython List Methods
- Python List index()
- Python List append()
- Python List extend()
- Python List insert()
- Python List remove()
- Python List count()
- Python List pop()
- Python List reverse()
- Python List sort()
- Python List copy()
- Python List clear()
Python Tutorials
- Python List sort()
- Python reversed()
- Python List remove()
- Python List clear()
- Python List insert()
- Python List
Python List reverse() The reverse() method reverses the elements of the list.
Example
# create a list of prime numbers prime_numbers = [2, 3, 5, 7] # reverse the order of list elements prime_numbers.reverse() print('Reversed List:', prime_numbers) # Output: Reversed List: [7, 5, 3, 2]Syntax of List reverse()
The syntax of the reverse() method is:
list.reverse()reverse() parameter
The reverse() method doesn't take any arguments.
Return Value from reverse()
The reverse() method doesn't return any value. It updates the existing list.
Example 1: Reverse a List
# Operating System List systems = ['Windows', 'macOS', 'Linux'] print('Original List:', systems) # List Reverse systems.reverse() # updated list print('Updated List:', systems)Output
Original List: ['Windows', 'macOS', 'Linux'] Updated List: ['Linux', 'macOS', 'Windows']There are other several ways to reverse a list.
Example 2: Reverse a List Using Slicing Operator
# Operating System List systems = ['Windows', 'macOS', 'Linux'] print('Original List:', systems) # Reversing a list # Syntax: reversed_list = systems[start:stop:step] reversed_list = systems[::-1] # updated list print('Updated List:', reversed_list)Output
Original List: ['Windows', 'macOS', 'Linux'] Updated List: ['Linux', 'macOS', 'Windows']Example 3: Accessing Elements in Reversed Order
If you need to access individual elements of a list in the reverse order, it's better to use the reversed() function.
# Operating System List systems = ['Windows', 'macOS', 'Linux'] # Printing Elements in Reversed Order for o in reversed(systems): print(o)Output
Linux macOS WindowsAlso Read:
- Python reversed()
- Python List sort()
Sorry about that.
How can we improve it? Feedback * Leave this field blankYour builder path starts here. Builders don't just know how to code, they create solutions that matter.
Escape tutorial hell and ship real projects.
Try Programiz PRO- Real-World Projects
- On-Demand Learning
- AI Mentor
- Builder Community
Python References
Python Library
Python List sort()
Python Library
Python List remove()
Python Library
Python List clear()
Python Library
Python List insert()
Tag » How To Reverse An Array Python
-
Reverse An Array In Python - 10 Examples - AskPython
-
How Do I Reverse A List Or Loop Over It Backwards? - Stack Overflow
-
Reversing A List In Python - GeeksforGeeks
-
Python | Reverse A Numpy Array - GeeksforGeeks
-
How To Use Python To Reverse A List Or Array - MakeUseOf
-
Python Reverse List – Reversing An Array In Python - FreeCodeCamp
-
Python Reverse List – How To Reverse A Range Or Array
-
Python Program To Print The Elements Of An Array In Reverse Order
-
Python Reverse NumPy Array
-
5 Methods To Reverse Array In Python (reverse, Recursion Etc)
-
Reverse The Array Using Python - PrepInsta
-
How To Reverse An Array In Python [Flip Array] - CodeItBro
-
NumPy: Reverse An Array - W3resource
-
Reverse An Array In Python Code Example - Code Grepper