Python List reverse() method
Description
The reverse() function reverses the elements in a list.
Syntax
reverse() method syntax:
list.reverse()
Parameters
- NA.
Return Value
This method has no return value, but reverses the order of the list's elements.
Example
The following example shows how to use the reverse() function:
Example
#!/usr/bin/python
aList
=
[
123
,
'xyz'
,
'zara'
,
'abc'
,
'xyz'
]
aList.
reverse
(
)
"List : "
,
aList
The output of the above example is:
List : ['xyz', 'abc', 'zara', 'xyz', 123]
Python Lists