Member-only story
Inheritance in Python OOP Explained Simply
If you’re reading this, I’m guessing that you’ve just started out with Object-Oriented Programming (OOP) in Python. The concept of inheritance in OOP might be pretty abstract and weird to someone who has little experience in this, so here’s my attempt at explaining it as simply as possible:
Inheritance — The “Is-A” Relationship
If there is inheritance, there needs to be a parent class and a child class. You can think of the parent class as a more general representation of a child class, and the parent and child classes have a “is-a” relationship.
For instance, we know that a dog is an animal. A cat is also an animal, and so is a bird. Animal here would be the parent class, and Dog (along with Cat and Bird) would be the child class, as Animal is a more general representation of Dog, Cat & Bird. Conversely, Dog is a more specific representation of Animal, and this is why Dog is the child class.
Here are a couple more parent-child class examples in case this in unclear:
- parent class: Animal — child classes: Dog, Cat, Bird
- parent class: Dog — child classes: ShibaInu, Mongrel, GermanShepherd
- parent class: Shape — child classes: Square, Rectangle, Circle
- parent class…