区分'方法'和'函数'

区分方法:

  1在类中的叫方法,在类外面的叫函数

  2在名字前加 对象名. 的叫方法,

    在名字前加 类名. 或 只写名字的 叫函数

通过代码进行区分:

1 from types import MethodType,FunctionType
2 def check(arg):
3     if isinstance(arg,MethodType)#判断第一个参数是否是第二个参数的实例
4         print('arg是一个方法')
5     if isinstance(arg,FunctionType)
6         print('arg是一个函数')

打印查看:

  function

  method

猜你喜欢

转载自www.cnblogs.com/leo-tail-x/p/9560871.html