Create Parent and Child Classes
The point is that they all inherit from
Animal, which you do with this syntax of parentheses, and then the name of the parent class. It’s also good practice to have two spaces between classes just to make it a little easier to read. We have a parent class
Animal, and three child classes, and then let’s make it a little less boring and define an initializer
def __init__(), and this takes
self. What else?
I’m going to stay with
color and assign them to instance attributes.
color. With this code, we have a parent class with two attributes so far, and then three child classes that inherit from it. That’s a good start, but how can we distinguish what is a
Dog and what is an
Become a Member to join the conversation.