Python callable() Function
Description
callable()This function is used to check whether an object is callable. If it returns True, the object may still fail to be called; but if it returns False, calling the object will definitely not succeed.
For functions, methods, lambda functions, classes, and__call__class instances that implement the method, it returns True.
Syntax
Syntax of callable():
callable(object)
Parameters
- object -- object
Return Value
Returns True if callable, otherwise returns False.
Examples
The following examples demonstrate the usage of callable():
>>>callable(0)
False
>>> callable("example")
False
>>> def add(a, b):
... return a + b
...
>>> callable(add) # Function returns True
True
>>> class A: # Class
... def method(self):
... return 0
...
>>> callable(A) # Class returns True
True
>>> a = A()
>>> callable(a) # Does not implement __call__, returns False
False
>>> class B:
... def __call__(self):
... return 0
...
>>> callable(B)
True
>>> b = B()
>>> callable(b) # Implements __call__, returns True
True
Python Built-in Functions