How to detect whether a Python variable is a function?

Sometimes, we want to detect whether a Python variable is a function.

In this article, we’ll look at how to detect whether a Python variable is a function.

How to detect whether a Python variable is a function?

To detect whether a Python variable is a function, we can call the callable function with the variable.

For instance, we write

is_func = callable(obj)

to call callable with obj to return True if obj is a function and False otherwise.

Conclusion

To detect whether a Python variable is a function, we can call the callable function with the variable.