Python List reverse()
Learn via video course

Overview
In Python, a list is an important and widely used data type. Multiple values can be stored in the list (that can be heterogeneous). Lists are mutable (inside values can be changed) and ordered(means the elements will remain in the same order as you have specified during a list declaration.
As a result of having so many features, we can also use reverse operation on the list. Reversing the list here refers to directly modifying the original list elements rather than creating a new list and copying the elements there in reverse order.
Syntax of reverse() in Python
In Python, a built-in function called reverse() is used to reverse the list. This is a simple and quick way to reverse a list in python, and it requires little memory.
Syntax: list_name.reverse()
Here, list_name means you have to write the list's name, which has to be reversed.
Note:- This reverse() function doesn’t return any value; it directly modifies the original list in-place means without creating a new list.
This function returns the None value as it modifies the original list directly. Let’s understand this with an example.
Code:
Output:
As shown in the script above, it is clear that the reverse() function directly modifies the original list in-place instead of returning a value.
There are pros and cons of this function:-
Pros- Extra Space is not required for storing the reversed list because of its in-place reversing feature.
Cons- This function overwrites the original list itself, so the original list can’t be accessed(it can only be retrieved after again reversing the string).
But the list can be copied before reversing the list in the new list so as to save the original list. This is done using the copy() function in python.
Let’s take an example:
As in the above example, there is a list that is Test_list; now, we have to reverse it. So we will no directly reverse the original list; we will first copy that list into another list that is New_list (using the copy() function) and then apply the reverse() function to it. So when we print that New_list, it will print the reversed list as an output.
Parameter of reverse() in Python
This reverse() function doesn’t need any parameter and just modifies the original list. We have to put the name of the list(that has to be reversed) along with the dot(.), then use this reverse() function.
As an example, you can refer to the previous one, where it is observable that reverse() is used there, which is not taking any parameter with it.
So it is clear that this reverse() function doesn’t need any kind of parameter.
Return Value of reverse() in Python
The reverse() function doesn’t return any value. This is because it directly modifies the original list in-place without creating a new list or space.
Let’s take an example:
As in the above script, we have stored the reversed value in the x, but as we know that it returns None, so when the x is printed, None comes out as an output. Whereas when test_list is printed, the reversed list comes as an output that has to be.
1st Method- Reverse a list in Python using list.reverse() method
This list.reverse() approach in python allows you to reverse a list in place. It makes in-place changes to the original list, so no extra memory is needed. The disadvantage is that the previous(original) list is changed.
In Python, a built-in function called reverse() is used to reverse the list. This simple and quick way to reverse a list in Python requires little memory.
Syntax: list_name.reverse() Here, list_name means you have to write the list's name, which has to be reversed.
Let’s take an example:
As in the above example, a list is Test_list; now, we have to reverse it. So we will no directly reverse the original list; we will first copy that list into another list that is New_list(using the copy() function) and then apply the reverse() function to it. So when we print that list(New_list), it will print the reversed list as an output.
This method is quick, straightforward, and self-explanatory. This would be the option I like to use whenever I need to reverse a list in-place and don't want to create an extra copy, but I don't mind modifying the original.
2nd Method- Reverse a list in Python using reversed() built-in function
This reversed() in-built function returns only the iterator, which is used to access the elements in the reversed order. In this function, no new list is created, and no original list is modified. This function takes the list as a parameter that has to be reversed.
The iterator iterates the whole given list in the reversed order so that the elements can be printed in that order or stored in the new list to print it later.
Syntax: reversed(list_name) Here, list_name means you must write the list's name, which must be reversed.
Let’s take an example.
Code:
Output:
As in the above example, there is a list named test_list, and we have used the reversed() function inside a 'for' loop, which helps to iterate over all the list elements in reverse order(iterator starts from the last elements and end it up to the first one).
But the problem here is that the elements are printed separately, and what if we want them all in the list in reversed order? So, we will call the list() constructor over the result of the reversed() function.
Elements can also be appended to the new list while iterating and then printed that new list at last. Let’s have an example.
Code:
Output:
Advantages:
- Returns an iterator that iterates the list in reverse order.
- Doesn’t need to modify the original list.
3rd Method- Reverse a list in Python using the slicing technique
As python comes up with an impressive feature that is list slicing. List slicing works with the syntax given below.
Syntax: list_name[start:stop:step] Here, list_name means you must write the list's name, which must be reversed. Start parameter indicates the value from where the user wants to slice the list or iterate it. Stop parameter indicates the value until the user wants to slice the list or iterate it. Step parameter indicates the value with which the user wants to skip the elements between the start and stop index of the list.
Let’s take an example:
- [: :] If you leave those parameters empty, it creates a copy of the list. Let’s take an example.
Code:
Output:
As you can see from the above script, start, stop, and step is passed as a parameter without any values inside them, which indicates that the list will normally iterate from the 0th index to the nth index with one as a step by default.
- [: : n] If you fill out the ‘step’ parameter only, it will create a copy, but that list(copy) will have every next nth element of the original list.
Let’s take an example.
Code:
As you can see from the above script, start and stop are passed as a parameter without any values inside them, but the step is passed with value '2', which means that this function will print the list from start to end with every 2nd element.
- [ : : -1] If you will pass -1 as a step parameter only, then it will print the list in reverse order. So we can use this to print the reversed list as given below.
Let’s take an example.
Code:
Output:
As you can see from the above script, start and stop are passed as a parameter without any values inside them. Still, the step is passed with value '-1', which means that the iterator will start iterating from the last element(5) until the first element(1).
From this approach, we are iterating all the elements in the list but in reverse order from stop to start.
But this approach has the drawback of creating a reversed copy of the list, which takes the memory.
Advantages
- Doesn’t modify the original list.
Conclusion
- There are many ways to reverse the list.
- We can use any of the methods depending upon the type of need.
- reverse() method reverses the list without creating a new copy but modifies the original list.
- reversed() function returns an iterator that iterates the list in reverse order.
- Slicing technique reverses the list without modifying the original list but takes extra space.