Python callable() Function with Examples

The term callable means that a object that can be called. The callable() built-in python function is used to check whether the object is callable...

In this tutorial we will discuss about the callable() function in python programming language with the help of examples.

Python callable() function

Python callable() function

The term callable means that a object that can be called. The built-in python function is used to check whether the object is callable or not. It returns if the object is callable. It returns if the object is not callable.

Syntax

callable(object)

Parameters of callable() function in python

The function in python takes only single parameter or argument i.e., object

Return value of Python callable() function 

The python callable() function is used to return following values;

• It returns if the object is .

• It returns if the object is .

Note: Even if the object is callable, sometimes calls to that object fails.

Example 1: How Python callable() Function works?

a = 7

print(callable(a))

def foo():

  print("Example")

b = foo

print(callable(b))

Output

False
True

In the above example, A object is not callable but B object seems to be callable (can also be not callable).

Example 2: Callable Object

class foo: 

    def __call__(self): 

        print('Python is Programming Language'

# Suggest that the foo class is callable

print(callable(foo)) 

# This means the class is callable 

pythonlang = foo() 

pythonlang()

Output

True
Python is Programming Language

Example 3: When Object is NOT Callable

class Foo:

def program(self):

    print('Python is Programming Language')

print(callable(Foo))

Output

True

Here, the instance of Foo class is not callable but it seems like callable. Therefore, an error will appear.

class Foo:

  def program(self):

    print('Python is Programming Language')

print(callable(Foo))

pythonLang = Foo()

pythonLang()

Output

True

Traceback (most recent call last):

  File "<string>", line 8, in <module>

TypeError: 'Foo' object is not callable