Tutorial Study Image

Python callable()

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
 

callable() Parameters:

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

callable () Return Value

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

Examples of callable () method in Python

Example 1: Passing a non-callable object with callable()


normalVariable = 1
print(callable(normalVariable))
 

Output:

False A normal variable is not a callable object

Example 2: Passing a callable object with callable()


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

Example 3: callable() method returns True to a non-callable object


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