What is the purpose of `__init_subclass__` in Python 3.6+?

Python Professional Hard

Python Professional — Hard

What is the purpose of `__init_subclass__` in Python 3.6+?

Key points

  • `__init_subclass__` is triggered when a class is subclassed
  • It allows customization for subclasses
  • It does not replace the `__init__` method
  • It does not prevent further subclassing

Ready to go further?

Related questions