Computer >> Computer tutorials >  >> Programming >> Python

callable() in Python Program


In this tutorial, we are going to discuss the built-in method callable(). It takes one argument and returns whether the argument is callable or not. If you take any function or class, they are callable. Constants like integers, floats, strings, etc.., are not callable.

Example

Let's see some examples.

 

# definition
def even(n):
   return True if n % 2 == 0 else False
# checking whether even() is callable or not
print(callable(even))

Output

If you run the above code, you will get the following results.

True

If you see, we can call the functions. So, the method callable() returns True. Let's see another example it returns False.

Example

# initializing a number
num = 7
# checking whether num is callable or not
print(callable(num))

Output

If you run the above program, you will get the following results.

False

We have got False for the integer value. Because we can't call the num like functions or classes. If you pass the class name to callable(), it will return True. Try it!

Conclusion

If you find any difficulty in understanding the tutorial, mention it in the comment section.