The built-in callable(obj) function returns True if obj can be called like a function, and False otherwise. Functions, methods, lambdas, classes and instances of classes that define __call__ are all callable.
Use it to validate callbacks, plugins and handlers before you invoke them. A True result is not a guarantee that the call will succeed, because the arguments may still be wrong, but a False result means the call will always raise TypeError.
The function takes one argument and returns a boolean. It was removed in Python 3.0, then restored in Python 3.2, so it is available in every current Python 3 release.
Note that str is callable because calling a class creates an instance. The built-in len is callable because it is a function implemented in C.
An object is callable if its type defines a __call__ method. Python functions and methods have one built in, and every class is callable through its metaclass.
| Object | callable() result |
|---|---|
| Function, lambda, built-in function | True |
Bound method, staticmethod result accessed on a class | True |
Class (including int, dict, your own classes) | True |
Instance of a class with __call__ | True |
Number, string, list, dict, None | False |
| Module | False |
Define __call__ on a class and its instances become callable. This is useful for objects that keep state between calls, such as counters, validators or configured formatters.
Here Multiplier is callable because it is a class, and double is callable because the class defines __call__. The attribute factor is just an integer, so it is not callable.
The most common use is checking an argument that should be a function. Failing early with a clear message is better than a confusing error deep inside your code.
You can also use callable to accept either a value or a factory, for example a default that is computed lazily when it is a function.
Python style prefers asking for forgiveness: call the object and catch TypeError. That approach has a flaw, because a TypeError raised inside the function body is indistinguishable from "not callable". Checking callable first separates the two cases.
For type hints, use collections.abc.Callable, which describes the expected signature to static checkers. It does not replace the runtime check.
Also avoid checking hasattr(obj, "__call__") in new code. callable() is shorter, clearer and checks the type, which is how Python itself finds __call__.
Yes. Calling a class creates an instance, so every class is callable, including built-in types such as int and list.
Yes. callable only checks that a call is possible in principle. Wrong arguments or errors inside the function still raise exceptions.
Use callable(getattr(obj, "name", None)). The default of None avoids an AttributeError when the attribute does not exist.
For practical purposes, yes: isinstance(obj, collections.abc.Callable) gives the same answer. The callable() built-in is the simpler choice.
callable(obj) tells you whether Python can call an object. Functions, classes and instances with __call__ are callable, while plain data values and modules are not. Use it to validate callbacks and lazy defaults, and pair it with collections.abc.Callable in type hints.