callable
Check whether an object can be called like a function.
Python 3.13
callable(object)Parameters
- objectAny
- The object to check.
Return value
True or False.
Examples
A function and a number
Python 3.13
print(callable(len), callable(42))True False
A class and an object with __call__
Python 3.13
class Greeter:
def __call__(self, name):
return f'Hi, {name}'
greeter = Greeter()
print(callable(Greeter), callable(greeter), greeter('Anna'))True True Hi, Anna
Details
Classes are callable: calling a class creates an object. An instance is callable only if its class has a __call__ method. True does not guarantee that the call succeeds, for example with the wrong arguments.
