英文文档
callable(object)
Return True if the object argument appearscallable, False if not. If this returns true, it is still possible that a callfails, but if it is false, calling object will never succeed. Note that classesare callable (calling a class returns a new instance); instances are callableif their class has a __call__() method.
callable()
1、方法用来检测对象是否可被调用,可被调用指的是对象能否使用()括号的方法调用。
>>> callable(callable)
True
>>> callable(1)
False
>>> 1()
Traceback (most recent call last):
File "<pyshell#87>", line 1, in <module>
1()
TypeError: 'int' object is not callable
2、可调用对象,在实际调用也可能调用失败;但是不可调用对象,调用肯定不成功。
3、类对象都是可被调用对象,类的实例对象是否可调用对象,取决于类是否定义了__call__方法。
>>> class