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

What is the usage of reverse() in python?

青灯夜游
Release: 2020-07-15 17:25:45
Original
61147 people have browsed it

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()
Copy after login

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
Copy after login

Output:

List :  ['xyz', 'abc', 'zara', 'xyz', 123]
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template