美文网首页
函数与方法

函数与方法

作者: 皮修猪 | 来源:发表于2018-04-15 19:22 被阅读0次

举例子:

>>>a = list('15325')

>>>a.sort()

>>>a

['5', '5', '3', '2', '1']

>>>b = list('8095')

>>>sorted(b)

>>>['0', '5', '8', '9']

一般而言, 我们把定义在对象中的函数称之为方法。只能特定的对象才能调用它.

这里,sort()就是list的方法,而sorted是python内置的函数。

相关文章

网友评论

      本文标题:函数与方法

      本文链接:https://www.haomeiwen.com/subject/othjkftx.html