Skip to content
Tutorials Center
My learning

Topics

Python Reference ยท Built-in Functions

Python callable() function

Reference for Python callable(): check whether an object can be called like a function, which objects qualify, how __call__ works and what the check cannot promise.

The built-in callable() function returns True if you can call the object with parentheses, like obj(), and False otherwise. Functions, methods, lambdas, classes and instances of classes that define __call__() are all callable.

It is useful when an argument may be either a value or a function that produces the value, such as a default factory or a callback.

Python
callable(len)     # True
callable("text")  # False

Try it

Python What can be called?

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Python Value or factory

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Syntax

Python
callable(object)
Name Description
object Any object.

Return value: True if the object's type defines __call__(), otherwise False.

Raises: nothing.

Usage notes

  • Classes are callable. Calling a class creates an instance, so callable(Dog) is True. An instance is callable only if its class defines __call__().
  • A true result is not a promise. callable(x) says a call is possible, not that it works with your arguments. The call can still raise TypeError for wrong arguments, or any error the function raises.
  • A false result is reliable. If callable() returns False, x() raises TypeError.
  • Instance attributes don't count. The check looks at the type, so setting obj.__call__ = ... on an instance does not make it callable.
  • Decorators. Many decorators accept either a function or arguments; callable() is a quick way to tell the two forms apart, though checking with inspect or a sentinel is more robust.
  • Typing. For type hints use collections.abc.Callable, for example Callable[[int], str].
  • Not the same as hasattr(x, "__call__"). Prefer callable(); it is clearer and checks the type.