Search code snippets, questions, articles...

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)
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place. Check how cool is the tool

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?
0 Comments