Callback is a python built-in function
English Description:
Callable (object)
Return True If the object argument appears callable,false if not. If this return true,it was still posssible that a call fails,but if it is false, calling object would never succeed. Note that classes is callable (calling a class returns a new Instence); Instance is callable if Theri class has a __call__ () method
Description
The 1 method is used to detect whether an object can be called, and can be called by means of whether the object can be called using () parentheses.
2 callable object may fail in actual invocation, but cannot invoke object, the invocation must not succeed
3 class objects are callable objects, whether an instance object of the class can be called, depending on whether the class defines the __call__ method
>>> class A: #定义类A pass>>> Callable (a) #类A是可调用对象True >>> a = A () #调用类A >>> Callable (a) #实例a不可调用False >>> a () #调用实例a失败Traceback (most recent): File "<pyshell#31>", Line 1, in <module> A () TypeError: ' A ' object was not callable>>> class B: #定义类B def __call__ (self): C4/>print (' instances is callable now. ') >>> callable (b) #类B是可调用对象True >>> B = B () #调用类B >>> callable (b) #实例b是可调用对象True >>> B () #调用实例b成功instances is callable now.
Reprint: https://www.cnblogs.com/sesshoumaru/p/5983979.html
The callable of Python