Review the Dog Class
Here we are. I have the code saved, and I will run the code in IDLE using F5. And now I’m over here in the interactive REPL, and I can play around with this
Dog class. Let’s start by creating one instance.
Woolf is 1 years old, so I get the name and the age of the dog. And then you also have access to a class attribute called
.species, which points to the string,
"Canis lupus familiaris", which is the scientific name for a dog. And to be precise, it’s actually a subspecies, not a species, because canis lupus is the gray wolf, and all dogs are just subspecies of gray wolf. But this approximation shouldn’t hurt anyone.
And that’s generally the better way to access a class attribute because if I would set this
woolf.species to something, I would create a new instance attribute and override the class attribute, basically. But let’s not go into this too much for now.
And then you have one more instance method that is called
.speak(), and this one takes as an attribute a sound and then returns a string that really just says the name of the dog and what sound they make.
This is the parent
Dog class that you’re going to be working with in the next review exercise. I hope you enjoyed that walk through the dog park, and see you over in the next lesson, where I get started with the exercises.
Become a Member to join the conversation.