方法和函数区别:
1、与类和实例无绑定关系的function都属于函数(function)
2、与类和实例有绑定关系的function都属于方法(methon)
一、方法sort()用于对数字的排序,他的对象是数字
方法sort()对列表进行永久性排序;

方法sort()不能对dict字典进行排序
二、sorted()函数用于对字符串的排序,他的对象是字符
函数sorted()对列表进行临时排序

对dict排序默认会按照dict的key值进行排序,最后返回的结果是一个对key值排序好的list

根据dict的value排序需要指定key参数


网友评论