This guide deals with the Python callable function and it’s uses, complete with several examples.
A callable object is an object that can be called by the Python program. The Python callable built-in function determines whether an object is callable or not. If it is callable, the function will return the Boolean value True. Otherwise, it returns False.
callable() function takes only a single argument as it’s parameter. This argument must be can object.
callable function only returns one of two values,
False. Depending on whether the object was callable or not.
Warning! The callable function is known to return True on some data types/objects which are not callable. However, any object that returns False is guaranteed to be non-callable.
In this example below we tried three different inputs for the
callable function. First we tried a Function, and the code returned True as Functions are callable. Next up we tried both strings and integers. However, we are well aware that they are not callable, hence they returned False.
def Food(): print("Hello Food") print(callable(Food)) print(callable(5)) print(callable("string"))
Output of the above code.
True False False
This marks the end of the Python callable Function Article. Any suggestions or contributions for CodersLegacy are more than welcome. Questions can be asked in the comment section below.
Here’s a link back to the main Python Built-in Functions page.