The reverse method

The reverse method returns a list in which the elements are rearranged in reverse order. We do not specify anything in the method parameter.

Syntax

pythonlist.reverse()

Example

Let's turn our list around:

pythonlst = ['ab', 'cd', 'ef']
lst.reverse()
print(lst)

Result of code execution:

python['ef', 'cd', 'ab']

See also

  • function len,
    which returns the length of the list
  • method copy,
    which copies the list
  • method clear,
    which removes all elements of a list