python检验一个对象是否可被调用
2018-03-15 本文已影响0人
whenitsallover
代码如下:
from types import FunctionType
a = 1
print(isinstance(a,FunctionType))
print(hasattr(a,'__call__'))
print(callable(a))
总共三种方法:
1、callable()
2、'_ call _'
3、isinstance(a,FunctionType)