Python List reverse()

In this tutorial, we will see about Python List‘s reverse method.Python List reverse method is used to reverse the list.

Python List reverse example

You can simply call reverse method to reverse the list.
Let’s understand this with the help of simple example.

Output:

listOfItems: [‘Clock’, ‘Bed’, ‘Fan’, ‘Table’] listOfItems in reversed order: [‘Table’, ‘Fan’, ‘Bed’, ‘Clock’]

As you can see here, list got reversed using reverse method.
There are other ways to reverse the list. You can use slicing to reverse a list.

Output:

listOfItems: [‘Clock’, ‘Bed’, ‘Fan’, ‘Table’] listOfItems in reversed order: [‘Table’, ‘Fan’, ‘Bed’, ‘Clock’]

If you just want to traverse in reverse order, you can use reversed function too.

Output:

Table
Fan
Bed
Clock

That’s all about Python List reverse method.

Related Posts

  • Initialize list with zeros in Python
    25 October

    Four Ways To Initialize List With Zeros In Python

    Table of ContentsWhy Initialize List with Zeros in Python?How Can We Initialize List With Zeros In Python?Initialize List With Zeros Using * Operator In PythonInitialize List With Zeros Using  itertools.repeat() FunctionInitialize List With Zeros Using  Generator Comprehension In PythonInitialize List With Zeros Using  List Comprehension In PythonConclusion Lists in Python are one of the most […]

  • 06 October

    How to find index of all occurrences in list in Python

    Table of ContentsThe easiest method – Using list count() methodThe Basic Method – Using for loopsThe shortest method – Using the enumerate() functionThe fastest method – Using a numpy arrayUsing itertools moduleUsing more-itertools LibraryUsing index() function List is a data type in Python. It is used to store multiple values in one variable. If you […]

  • Convert list to matrix in Python
    21 August

    Convert list to matrix in Python

    Table of ContentsUsing the while loop to convert list to matrix in Python.Use the numpy.array() method to convert list to matrix in Python.Using the numpy.asarray() method to convert list to matrix in Python. Python provides some in-built data types to stock multiple items in a single variable. A List is one among these built-in data […]

  • Sort list alphabetically in Python
    31 May

    Sort list alphabetically in Python

    Table of ContentsUse of the sort() function to sort list alphabetically in Python.Use of the sorted() function sort list alphabetically in Python.Use of the QuickSort algorithm sort list alphabetically in Python. 💡 Outline You can use sort() method of list to sort list alphabetically in Python [crayon-617908406c07c763593060/] In this tutorial, we will discuss different ways […]

  • Find common elements in two lists Python
    25 May

    Find common elements in two lists in python

    Table of ContentsUsing the intersection() FunctionUsing List ComprehensionUsing & Operator 💡 Outline You can first convert first list into set using set() and call intersection() by passing second list as parameter to find common element in two lists in Python. [crayon-617908406d13e852235733/] In this tutorial, we will see different methods to find common elements in two […]

  • 11 April

    Python Remove Newline from List

    Table of ContentsIntroduction✨ Method 1: Using the replace() method✨ Method 2: Using re.sub()✨ Method 3: Using strip()✨ Method 4: Slice the List Elements✨ Method 5: Using List Comprehension and Splitlines Function✨ Method 6: Using str.maketrans(x,y) and str.translate(map)Conclusion 🎯 Objective: In this article, we will discuss the methods to remove ‘\n’ or newline characters from a […]

Leave a Reply

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

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.