Finding out whether an object is callable
In this section, we will look at another built-in function named callable
. As the name implies, this function helps in identifying whether a Python object can be called. Functions and methods can be called to enable various operations to be performed on the input parameters. Not all Python objects are callable. For example, a string variable or a numeric variable stores information but will not perform any action when executed. The callable
function helps in verifying such objects that can be called and those that cannot be called in a function.
Why do we need to check whether an object is callable? Python is an object-oriented programming language where we can write libraries and write classes within the libraries that are encapsulated. The end user of classes or libraries need not always have access to the class definition or method definitions. While importing the Python libraries, we might sometimes want to know whether the imported...