
如何判断一个对象是函数还是方法?
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
👁️ 阅读量:0
© 版权声明:本文《如何判断一个对象是函数还是方法?》内容均为本站精心整理或网友自愿分享,如需转载请注明原文出处:https://www.zastudy.cn/wen/1686493418a269245.html。