Python inheritance: When to use it and when to prefer composition

Python inheritance: When to use it and when to prefer composition

When should you use inheritance in Python?

– An existing class mostly does what you want
– Inheriting reduces your work — you only define differences
– It’s an IS-A relationship, not just HAS-A
– Otherwise: prefer composition.

Remember: Inheritance is a tool, not a default.