Python 3 reference · Built-in Functions
Python callable() Function
Return True if an object can be called like a function: functions, classes, methods and objects with __call__().
Python 3 Since 3.2
Syntax
callable(object)
Parameters
| Parameter | Description |
|---|---|
object |
Any object. |
Return value
True if the object appears callable, otherwise False.
Examples
print(callable(print))
print(callable(len))
print(callable(int)) # classes are callable
print(callable(42))
print(callable("hello"))
Output
True True True False False
class Greeter:
def __call__(self, name):
return f"Hello, {name}"
greet = Greeter()
print(callable(greet), greet("Ada"))
Output
True Hello, Ada
Good to know
callable() was removed in Python 3.0 and brought back in Python 3.2. A True result means calling is
possible, not that it will succeed with the arguments you pass.
Version history
| Version | Change |
|---|---|
| Python 3.2 | Added |
Related
isinstance()· Return True if an object is an instance of a class, one of its subclasses, or any class in a tuple or union of classes.type()· With one argument, return an object's type. With three arguments, create a new class dynamically.- Python Functions · tutorial