The callable() method checks if a object is callable. Callable objects are True if object is callable and False if object is not callable.
Syntax & Parameters
callable(object)
The callable() method takes one argument, an object and returns one of the two values:
- returns True, if the object appears to be callable.
- returns False, if the object is not callable.
Example
def callIt():
return 1
# CReating object
ex = callIt
print(callable(ex))
#Not Callable
x= 1
print(callable(x))
Output
True
False
class Foo:
def __call__(self):
print(callable(ex))
ex = Foo()
ex() #calling callable
Output
True