How to Reverse List Elements in Python Examples

In this tutorial, learn how to change or reverse list element using Python. The short answer is: use the Python reverse() function to reverse the order of the list elements.

The reverse method changes the order of the list elements. You can change the location of the list elements and print the elements from last to start. You can also use the Python loop to change the order of the list elements.

How to Reverse List Element With Python Reverse()

If you want to change the order of the list elements, you have to use the Python reverse(). Use the list variable followed by the reverse function to reverse the order.

See the example below to change the order of the list elements.

Output

[51, ‘four’, 37, ‘two’, ‘one’]

The above example prints the list elements with the reversed order. You have to use the above-given example to change your list elements order.

However, you can learn and use the loop to change the order of the list elements in the next section.

Change Position of List Items With For Loop and Reversed() in Python

To reverse the list elements, you have to use the Python for loop and reversed() function. You can use the below-given example to learn this method as per your requirement.

Output

51
four
37
two
one

The above example showing the elements printed the output with reverse order. The loop method prints the reversed elements in the output with a single element in a single line.

You can also use this method to access the list elements in reverse order.

Change Order of List Elements With Slice Operator

In addition to above all methods, you can also use the slice operator to reverse the list order. To perform this, you have to use the below-given example and change the list with your list.

Output

[51, ‘four’, 37, ‘two’, ‘one’]

The above examples showing the same output as you get with the reverse() function. The example store the reversed list to the other variable. After that, it prints the reversed list using the print statement of Python.

You may also like to read

Hope, you like this post of how to reverse the list elements in Python. If you have any query regarding the tutorial, please comment below.

Also tell me, which method you are using to reverse the order of your list elements.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.