class A:
    def func(self):
        pass
print(A.func)  #类调用动态属性是函数
a = A()
print(a.func)   #对象调用动态属性是方法

from types import MethodType, FunctionType       
print(isinstance(a.func,MethodType)) print(isinstance(A.func,MethodType)) print(isinstance(a.func,FunctionType)) print(isinstance(A.func,FunctionType))

执行结果:

<function A.func at 0x0000018A0C9FB8C8>
<bound method A.func of <__main__.A object at 0x0000018A0C9F9358>>
True
False
False
True

通过以上结果总结:

#类调用动态属性是函数
#对象调用动态属性是方法

相关文章:

  • 2021-10-15
猜你喜欢
  • 2021-10-15
  • 2021-10-25
  • 2021-10-15
  • 2021-10-15
  • 2021-08-08
  • 2021-08-07
  • 2021-08-07
相关资源
相似解决方案