Exercising Your New Knowledge
00:00 As with most things, but especially with classes, you need to exercise your new knowledge to make it stick and to include it—to be able to include it—as part of your tool kit when you go forward.
Create a new class, a
Car class, with a few instances that would be appropriate for cars. Add a
.mileage attribute to the
Car class, and then add a
.drive() instance method to the class, which will add a number of miles to the mileage. So if you instantiate a car—I don’t know, a Ford—and then you say
ford.drive(), and you pass in, say,
10 to that method, if you look at the
ford.mileage, you’ll see that
10 has been added to the mileage, which might have started out at
0, or maybe the starting mileage is something that you can pass in to the constructor.
01:28 It’s one thing just to look through and say, yep, I understand that. Yep, I understand that. Yep, I understand that. But when you actually come to a blank script and have to actually write this stuff and get it working, that’s when you realize, oh, I didn’t understand that part. So definitely give that a shot.
Become a Member to join the conversation.