Functional Behavior of an Object

Details on callable objects in Python.

We'll cover the following

In the beginning of this chapter, we covered in detail that functions are objects, but the reverse isn’t true. Not every object is a function, but Python allows us to use callable objects. It means that an object can behave like a function. Let us dive into the details to see how this is possible.

Callable objects

The callable objects are the objects that can be called like a function (using ()), and can be passed as an argument in a function call. This is made possible with the __call__ method. Look at the following example to see how to define a callable object.

Get hands-on with 1200+ tech skills courses.