Home >Backend Development >Python Tutorial >What is the usage of reverse() in python?

What is the usage of reverse() in python?

青灯夜游
青灯夜游Original
2020-07-15 17:25:4561145browse

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.

What is the usage of reverse() in python?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn