参考:http://www.runoob.com/python/att-list-sort.html
描述
sort() 函数用于对原列表进行排序,如果指定参数,则使用比较函数指定的比较函数。
语法
sort()方法语法:
list.sort([func])
参数
func – 可选参数, 如果指定了该参数会使用该参数的方法进行排序。
返回值
该方法没有返回值,但是会对列表的对象进行排序。
实例
以下实例展示了 sort()函数的使用方法:
list1 = ['123', 'xyz','456' ,'zara', 'abc', 'xyz']
list2 = [1,6,3,5,4,8,2,10,9]
list1.sort()
list2.sort()
print("list1 : ", list1)
print("list2 : ", list2)
以上实例输出结果如下:
list1 : ['123', '456', 'abc', 'xyz', 'xyz', 'zara']
list2 : [1, 2, 3, 4, 5, 6, 8, 9, 10]