Latest web development tutorials

Python3 List sort () method

Python3 list Python3 list


description

sort () function is used to sort the list of the original, if the specified parameter, the comparison function specified compare function.

grammar

sort () method syntax:

list.sort([func])

parameter

  • func - optional parameter, if the parameter Use this parameter to specify the method to sort.

return value

This method does not return a value, but the target list will be sorted.

Examples

The following example shows the sort () function to use:

#!/usr/bin/python3

list1 = ['Google', 'w3big', 'Taobao', 'Baidu']
list1.sort()
print ("列表排序后 : ", list1)

Examples of the above output results are as follows:

列表排序后 :  ['Baidu', 'Google', 'w3big', 'Taobao']

Python3 list Python3 list