reverse() is a built-in method in python lists, used to reverse elements in the list; syntax: "list.reverse()". The reverse() method has no return value, but it sorts the elements of the list in reverse order.
reverse() is a built-in method in python lists (that is, there is no such built-in method in dictionaries, strings or tuples ), used to reverse the elements in the list.
Syntax
reverse() method syntax:
list.reverse()
Parameters: NA.
Return value
This method has no return value, but it will sort the elements of the list in reverse order.
Example:
#!/usr/bin/python aList = [123, 'xyz', 'zara', 'abc', 'xyz'] aList.reverse() print "List : ", aList
Output:
List : ['xyz', 'abc', 'zara', 'xyz', 123]
Recommended learning: Python video tutorial
The above is the detailed content of What is the usage of reverse() in python?. For more information, please follow other related articles on the PHP Chinese website!