Home > Backend Development > Python Tutorial > What does sort mean in python?

What does sort mean in python?

藏色散人
Release: 2019-08-01 15:37:56
Original
36146 people have browsed it

What does sort mean in python?

What does sort mean in python?

The sort() function in python is used to sort the original list , if the argument is specified, the comparison function specified by the comparison function is used.

Syntax

sort() method syntax:

list.sort(cmp=None, key=None, reverse=False)
Copy after login

Parameters

cmp -- Optional parameter, if specified Parameters are sorted using the parameter's method.

key -- Mainly used for comparison elements, with only one parameter. The parameters of the specific function are taken from the iterable object, and an element in the iterable object is specified for sorting.

reverse -- Sorting rule, reverse = True for descending order, reverse = False for ascending order (default).

Return value

This method has no return value, but it will sort the objects in the list.

The following examples show how to use the sort() function:

#!/usr/bin/python
# -*- coding: UTF-8 -*-
 
aList = [123, 'Google', 'Runoob', 'Taobao', 'Facebook'];
 
aList.sort();
print "List : ", aList
Copy after login

The output results of the above examples are as follows:

List :  [123, 'Facebook', 'Google', 'Runoob', 'Taobao']
Copy after login

Related recommendations: "PythonTutorial

The above is the detailed content of What does sort mean 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