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

What does sort mean in python?

藏色散人
藏色散人Original
2019-06-26 10:03:0736145browse

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)

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

The output results of the above examples are as follows:

List :  [123, 'Facebook', 'Google', 'Runoob', 'Taobao']

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!

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