Home >Backend Development >Python Tutorial >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!