1 00:00:00,790 --> 00:00:03,190 The following content is provided under a Creative 2 00:00:03,190 --> 00:00:04,730 Commons license. 3 00:00:04,730 --> 00:00:07,030 Your support will help MIT OpenCourseWare 4 00:00:07,030 --> 00:00:11,390 continue to offer high-quality educational resources for free. 5 00:00:11,390 --> 00:00:13,990 To make a donation or view additional materials 6 00:00:13,990 --> 00:00:17,880 from hundreds of MIT courses, visit MIT OpenCourseWare 7 00:00:17,880 --> 00:00:18,840 at ocw.mit.edu. 8 00:00:23,160 --> 00:00:26,180 ANA BELL: So we're given this definition for car. 9 00:00:26,180 --> 00:00:27,750 We saw that on the previous slide. 10 00:00:30,790 --> 00:00:34,300 I want to add a method that's going 11 00:00:34,300 --> 00:00:38,650 to change the color of the car, and these are my four choices. 12 00:00:38,650 --> 00:00:40,990 And it looks like you guys are getting it 13 00:00:40,990 --> 00:00:43,296 right, which is awesome. 14 00:00:43,296 --> 00:00:45,670 So to find a method to change the color of the car, which 15 00:00:45,670 --> 00:00:47,110 does this. 16 00:00:47,110 --> 00:00:51,530 So we know that self has to be the first parameter, 17 00:00:51,530 --> 00:00:53,880 so we can automatically eliminate A and C 18 00:00:53,880 --> 00:00:59,214 and it's between B and D. And remember 19 00:00:59,214 --> 00:01:01,630 I said you have to be conscious about whose data attribute 20 00:01:01,630 --> 00:01:03,590 you're accessing, and in this case, 21 00:01:03,590 --> 00:01:07,150 we want to change the color of a particular instance of the car, 22 00:01:07,150 --> 00:01:07,840 right? 23 00:01:07,840 --> 00:01:12,500 So we have to say self.color instead of just color. 24 00:01:12,500 --> 00:01:14,600 If we just said color, then color 25 00:01:14,600 --> 00:01:20,430 would refer to just a variable inside the class, 26 00:01:20,430 --> 00:01:24,950 not a data attribute of a particular object.