The list.reverse()
method is simply used to reverse the order of the items in a list in Python.
list.reverse()
There are no parameter values.
Let’s create a list of even numbers up to ten and then use the list.reverse()
method to reverse the order of the items in the list.
even_numbers = [2, 4, 6, 8, 10]# now let us reverse the items in the listeven_numbers.reverse()print(even_numbers)
even_numbers
.list.reverse()
method to reverse the items on the list using even_numbers.reverse()
.Let’s reverse the order of items present in a list of countries.
countries = ['Argentina', 'Niger', 'Italy', 'Russia', 'Australia']# reversing the order of the items in the listcountries.reverse()print(countries)