Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Python · Module

__call__

Defining __call__ on a class makes its instances callable like functions. Calling an instance dispatches to the class’s __call__ method with the instance and supplied arguments.

How it works

Define __call__ on a class to give its instances function-like invocation. When an instance x is called with arguments, Python dispatches to the class’s __call__ implementation with x as the first argument, so the method can use instance state and return the call result.

Syntax

object.__call__(self [, args...])

Parameters

NameTypeDescription
selfobjectThe instance that receives the call.
argstupleOptional positional arguments supplied by the caller.

Returns

The value returned by the class's __call__ implementation; the documentation does not prescribe a particular return type.

Key points

  • Adding __call__ to a class makes its instances usable with ordinary function-call syntax.
  • Python invokes __call__ when code uses the instance as the callee.
  • The call operation conceptually looks up __call__ on the instance’s type and passes the instance first.
  • Function-call syntax is defined for callable objects, and a user-defined instance becomes one through __call__.

Common mistakes

  • There is no inherited default implementation from object; a class must define __call__ or inherit it from another class if its instances should be callable.

Example: A callable instance

class Multiplier:
    def __init__(self, factor):
        self.factor = factor

    def __call__(self, value):
        return self.factor * value


double = Multiplier(2)
print(double(5))  # 10

The instance can be invoked with function-call syntax because its class defines __call__.

When to use it

Stateful callable

A configured operation needs to be reused with function-call syntax while retaining instance attributes.

Callback object

An object should present a simple operation interface to APIs that accept callable objects.

Function-like object

A class should model a reusable transformation whose configuration is supplied at construction time.

Interview questions

QWhat does __call__ do?

Defining __call__ makes instances of a class callable. Calling x(arg1, arg2) dispatches approximately to type(x).__call__(x, arg1, arg2).

Follow-up: How can you check this property at runtime? Use callable(x), which tests whether the object can be used with call syntax.

QWhat is the signature of object.__call__?

The first parameter is self, representing the instance being called. Additional positional arguments are conventionally captured by *args, as shown by the documented object.__call__(*self [, *args...*]) form.

Follow-up: How would keyword arguments be supported? Define the method with **kwargs, or with explicit keyword parameters, according to the desired interface.

QWhy use a callable object instead of a plain function?

A callable instance can retain configuration in attributes and apply that state whenever it is invoked. This provides function-like use while keeping object state and behavior together.

Follow-up: What does the documentation say about object.__call__ itself? The object class has no implementation; the behavior comes from the class defining or inheriting the method.

  • callable()
  • object
  • type
  • Calls
  • user-defined classes

Source: 3. Data model — Python 3.15.0 documentation. Checked 2026-10-16.