admin管理员组

文章数量:1794759

如何判断一个对象是函数还是方法?

如何判断一个对象是函数还是方法?

from types import MethodType, FunctionType class Bar: def foo(self): pass def foo2(): pass def run(): print("foo 是函数", isinstance(Bar().foo, FunctionType)) print("foo 是方法", isinstance(Bar().foo, MethodType)) print("foo2 是函数", isinstance(foo2, FunctionType)) print("foo2 是方法", isinstance(foo2, MethodType)) if __name__ == '__main__': run() foo 是函数 False foo 是方法 True foo2 是函数 True foo2 是方法 False

 

本文标签: 函数如何判断方法