all Python 3inspectfunction
inspect.isfunction()
object kind checks
Checks that an object is a function written in Python (def or lambda), that is types.FunctionType.
Syntax
inspect.isfunction(object) -> bool
This is not 'can I call it': built-ins like len and print, bound methods, functools.partial and classes all give False. A method taken from the class (A.m) is a plain function, while from an instance (a.m) it is already a method that isfunction does not recognize. For 'is it callable' use callable(), for 'a function or method of any origin' use isroutine().
Examples
import functools, inspect
class A:
def m(self): pass
print(inspect.isfunction(A.m), inspect.isfunction(A().m)) # → True False
print(inspect.isfunction(lambda: 0), inspect.isfunction(len)) # → True False
print(inspect.isfunction(functools.partial(print)), callable(len)) # → False True
See also
Open in the full glossarydocs.python.orgReport an inaccuracy