Categories
Python Answers

How to detect whether a Python variable is a function?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *