April 2014
Beginner to intermediate
634 pages
15h 22m
English
Python's definition of
callable object includes the obvious function definitions created with the def statement.
It also includes, informally, any class with a __call__() method. We can see several examples of this in Python 3 Object Oriented Programming, Dusty Phillips, Packt Publishing. For it to be more formal, we should make every callable class definition a proper subclass of collections.abc.Callable.
When we look at any Python function, we see the following behavior:
>>> abs(3) 3 >>> isinstance(abs, collections.abc.Callable) True
The built-in abs() function is a proper instance of collections.abc.Callable. This is also true for the functions we define. The following is an example:
>>> def test(n): ... return n*n ... >>> isinstance(test, ...