callable() Builtin Function

Python – callable()

Python callable() builtin function returns a boolean value of True if the given argument is callable, or False if not.

Syntax

The syntax of callable() function is

callable(object)

where object is any Python object.

Examples

callable() with function as argument

In the following program, we define a function sayHello(), and programmatically check if this function object is callable using callable() builtin function. Since, a function is callable, callable(sayHello) must return True.

Python Program

def sayHello():
    print('hello user')

output = callable(sayHello)
print(f'callable() : {output}')
Run

Output

callable() : True

callable() with integer as argument

An integer value is not a callable object. Therefore, callable() with integer passed as argument returns False.

Python Program

object = 52
output = callable(object)
print(f'callable() : {output}')
Run

Output

callable() : False

callable() with builtin function as argument

print() is an inbuilt function and callable. Therefore, print as an argument to callable() returns True.

Python Program

output = callable(print)
print(f'callable() : {output}')
Run

Output

callable() : True

callable() with lambda function as argument

Lambda function is a callable function. callable() with lambda function passed as argument must return True.

Python Program

sayHello = lambda : print('hello user')
output = callable(sayHello)
print(f'callable() : {output}')
Run

Output

callable() : True

Summary

In this tutorial of Python Examples, we learned the syntax of callable() function, and how to check if given object is callable or not, with examples.