- 被用来检查是否是可调用的对象
- 一般可调用的对象都会有魔法方法
__call__
- 当前方法返回布尔值,如果是可调用的对象返回
True
,不可调用的对象返回False
def fn():
pass
_number = 10
class A:
pass
class B:
def __call__(self):
pass
print(callable(fn)) # True
print(callable(_number)) # False
a = A()
b = B()
print(callable(a)) # False 内部没有__call__
print(callable(b)) # True 内部有__call__