What is the purpose of `__call__` in a Python class?

Python Professional Hard

Python Professional — Hard

What is the purpose of `__call__` in a Python class?

Key points

  • `__call__` enables instances to be treated as functions
  • It is not called when the class is defined or when the instance is garbage collected
  • It does not override the class constructor

Ready to go further?

Related questions