python

Reverse a list items in Python

To reverse the order of all the items of a list in Python, you can use List.reverse() function. Below is the code example for that.

my_list = ['John', 'herry', 'Carl', 'Morgan']

my_list.reverse()

print(my_list)

Output

['Morgan', 'Carl', 'herry', 'John']

The reverse() function of the Python list returns the reversed order or iterated elements.

In the code snippet,

  1. We have defined a list(my_list).
  2. We are using List.reverse() function to reverse all the elements of the list.
  3. Printing the list(my_list) that contains the reverse order of elements.
Was this helpful?