reverse() method reverse the positions of elements of list

reverse() takes no arguments .

It does not take any arguments and modifies the original list, returning the elements in reverse order. This method is useful when you want to flip the arrangement of list items quickly.
my_list=['a','b','c','d','x','y','z']
my_list.reverse()
print(my_list)
Output
['z', 'y', 'x', 'd', 'c', 'b', 'a']
Reversing Numeric Lists:
This example flips the order of numbers in the list.
numbers = [1, 2, 3, 4, 5]
numbers.reverse()
print(numbers)  # Output: [5, 4, 3, 2, 1]
Use Case: Undoing Sorting: If you've sorted a list and want to restore its original order:
items = ['apple', 'banana', 'cherry']
items.sort()      # ['apple', 'banana', 'cherry']
items.reverse()   # ['cherry', 'banana', 'apple']
Reversing String Lists:
words = ['one', 'two', 'three']
words.reverse()
print(words)  # Output: ['three', 'two', 'one']

Example 1: Reversing a List of Numbers

my_list = [1, 2, 3, 4, 5]
my_list.reverse()
print(my_list)  # Output: [5, 4, 3, 2, 1]

Example 2: Combining sort() and reverse()

my_list = [4, 2, 9, 1]
my_list.sort()
my_list.reverse()
print(my_list)  # Output: [9, 4, 2, 1]

Example 3: Reversing a List with Mixed Data Types

my_list = [1, "apple", 3.14]
my_list.reverse()
print(my_list)  # Output: [3.14, 'apple', 1]

Use the reverse() method for in-place modification of lists, which is efficient when working with data that needs quick reordering.
All list methods Questions with solutions on List
Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com







Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer