from types import MethodType, FunctionType
class Foo(object):
def __init__(self):
self.name = "MyName"
def func(self):
print(self.name)
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
print(type(obj.func)) # <class 'method'>
print(type(Foo.func)) # <class 'function'>
REF
https://www.zhihu.com/question/317390856/answer/632194800