AI engineering glossary · Python advanced
What is __call__?
__call__: The special method that lets an object be called like a function using parentheses. It is useful for objects that carry state between calls, such as configured models or decorators implemented as classes.
__call__: an example
class Scale: def __call__(self, x): return x * self.k; double = Scale(2); double(5) returns 10.
Related terms
- Dunder method
- Callable
- Decorator
- Closure
More Python advanced terms
Where you learn it
__call__ is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.