Create a Child Class (Solution)
To create a child class from a class, what you need to do is, again, use the
class keyword, then type in the name of your class, so
GoldenRetriever, and then you can open up parentheses here and then put in the parent class and then close the parentheses and finish it off with a colon as usual. In the next line, I’m going to for now put a
pass keyword just to satisfy Python’s need for some indented code after a colon, but I’m not going to implement any functionality in the child class so far.
and jump over in the interactive shell. And now I’m going to make a
GoldenRetriever. We call him,
GoldenRetriever() and again, it needs a name and an age. We called him
buddy, so let’s stick with that. It’s an old dog,
12 years old. No complaints.
So now I have an instance of
GoldenRetriever. Here you can also see that if I
print() the representation of
Buddy, then it says in the main namespace, I have a
GoldenRetriever object at a certain memory location.
Become a Member to join the conversation.