16 of 151 menu

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

list.reverse()

Example

Let's turn our list around:

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

Result of code execution:

['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
byenru