The callable function in python checks whether the parameter passed is a callable object or not. If the parameter is callable returns True else returns False
callable(obj) #Where obj is any python object
The callable function in python takes only one mandatory parameter, the parameter can be any object in python.
Parameter | Description | Required / Optional |
---|---|---|
object | The method checks whether the object is callable or not | Required |
The return value is false when the input is not callable. Generally, the method returns True if the passed object is not callable. But in certain cases, the method may return true even if the object is not callable (see example 3)
Input | Return Value |
---|---|
Callable object | True |
The object is not callable | False |
normalVariable = 1
print(callable(normalVariable))
Output:
False A normal variable is not a callable object
def callableFunction():
print("Hii ..I am a callable function")
print(callable(callableFunction))
callableFunction() #Calling the function to check
Output:
True Hii ..I am a callable function
class NonCallableClasscheck:
def method_of_class():
print(“Hii.. I am a method of NonCallableClasscheck”)
print(callable( NonCallableClasscheck))
InstanceofClass = NonCallableClasscheck()
InstanceofClass() #Calling the object to check
Output:
True TypeError: 'NonCallableClass' object is not callable