#Using the callable() function
def func():
print("Hello")
a = 10
print(callable(func)) #is func callable?
print(callable(a)) #is a callable?
The callable()
function checks if an object is callable, i.e. if it is a function, a method, a lambda function, or a class. It takes a single argument and returns a boolean value (True
or False
).
callable(obj)
obj |
The object to check whether it can be called all not. |
The function returns a boolean value. True
if the object is callable, False
otherwise.
Examples:
def func():
pass
callable(func)
//True
L = [1, 2, 3]
callable(L)
//False
callable(print)
//True