sort()方法排序列表中的对象,使用 func 比较(如果给定)。
语法
下面是 sort()方法的语法 -
list.sort([func])
参数
NA
返回值
此方法不返回任何值,但反转列表中给定的对象。
示例
下面的示例演示 sort()方法的使用。
#!/usr/bin/python3 list1 = ['physics', 'Biology', 'chemistry', 'maths'] list1.sort() print ("list now : ", list1)
当我们运行上面的程序,会产生以下结果 -
list now : ['Biology', 'chemistry', 'maths', 'physics']
上一篇:
Python3字符串
下一篇:
Python3列表