Callable Objects
Learn how to make the objects callable with the help of coding examples.
Overview
Just as functions are objects that can have attributes set on them, it is possible to create an object that can be called as though it were a function. Any object can be made callable by giving it a __call__()
method that accepts the required arguments.
Example
Let’s make our Repeater
class (Repeater_2
), from the timer example, a little easier to use by making it a callable, as follows:
Access this course and 1400+ top-rated courses and projects.