- 函数和方法?

class Foo(object):
def __init__(self):
self.name = 'alex'
def func(self):
print(self.name)

from types import FunctionType,MethodType

obj = Foo()
print(isinstance(obj.func,FunctionType)) # False
print(isinstance(obj.func,MethodType)) # True

print(isinstance(Foo.func,FunctionType)) # True
print(isinstance(Foo.func,MethodType)) # False

  


注意:
方法,无需传入self参数
函数,必须手动传入self参数

相关文章:

  • 2022-12-23
  • 2022-03-06
  • 2021-09-04
  • 2021-08-06
  • 2021-06-20
  • 2022-03-04
猜你喜欢
  • 2021-05-22
  • 2022-12-23
相关资源
相似解决方案