Creating the Dog Class (Trial)
00:00 Let’s try it out. Press F5 to run the file, and it puts me into the interactive mode over here, which has the information of this file of the class that I defined.
00:11 This is specific to IDLE, so if you are using a different editor, then just make sure to print it down here in the file before you run it here. I get the chance to play with it a bit, so I can create a dog.
00:24
I’ll call the dog "Philo"
, and it’s 12 years old. This is what I get returned. I get a Dog
object. Now I should be able to print()
, well, I should assign it to something, right? That’ll make it easier.
00:41
So I assigned the Dog
instance to the variable philo
, and then I should be able to print(philo)
. So this is going to call .__str__()
, and you see the f-string returned: Philo
, the name of the dog is 12 years old
, so that’s a nice representation.
00:58
The other task was that I should be able to call .speak()
on it and pass it a sound. "Wau"
.
01:07
There it is, my string Philo says Wau
. This is just a re-creation of the Dog
class that you built in the Python Basics: Object-Oriented Programming Course.
01:17 And this is what we’re going to start with with the next review exercise, but it’s always a good review exercise also to redo some code that you’ve already built before, because if you start from scratch, there’s always going to be a little bit of thinking involved.
01:31 If you ended up with something that looks like this, then great job. This is the code that I’m going to continue working with in the next exercise as well. Let’s get going and look at the next task.
Become a Member to join the conversation.