Home > Article > Backend Development > python function callable(object)
Chinese description: Check whether the object object is callable. If True is returned, object may still fail to be called; but if False is returned, calling object object will never succeed.
Note: The class is callable, and the instance of the class can only be called if it implements the __call__() method.
Version: This function is available in python2.x version. However, it was removed in python3.0 and re-added in python3.2 and later versions.
English description:Return True if the object argument appears callable, False if not. If this returns true, it is still possible that a call fails, but if it is false, calling object will never succeed. Note that classes are callable (calling a class returns a new instance); class instances are callable if they have a __call__() method.
Code example:
>>> callable(0) False >>> callable("mystring") False >>> def add(a, b): … return a + b … >>> callable(add) True >>> class A: … def method(self): … return 0 … >>> callable(A) True >>> a = A() >>> callable(a) False >>> class B: … def __call__(self): … return 0 … >>> callable(B) True >>> b = B() >>> callable(b) True
The above is the detailed content of python function callable(object). For more information, please follow other related articles on the PHP Chinese website!