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,890 from hundreds of MIT courses, visit MIT OpenCourseWare 7 00:00:17,890 --> 00:00:18,850 at ocw.mit.edu. 8 00:00:23,638 --> 00:00:26,830 PROFESSOR: We have this definition 9 00:00:26,830 --> 00:00:29,470 for the class object. 10 00:00:29,470 --> 00:00:33,100 I've created the init for you. 11 00:00:33,100 --> 00:00:34,690 And here I'm giving it "self," which 12 00:00:34,690 --> 00:00:36,610 is the first thing that you have to give it, 13 00:00:36,610 --> 00:00:40,200 and then two parameters-- w and d. 14 00:00:40,200 --> 00:00:44,240 And for an instance of a car, I'm 15 00:00:44,240 --> 00:00:47,270 going to assign the data attribute named wheels 16 00:00:47,270 --> 00:00:49,790 to whatever is passed in for w. 17 00:00:49,790 --> 00:00:52,840 So notice that they're not the same name. 18 00:00:52,840 --> 00:00:54,610 And the data attribute for "doors" 19 00:00:54,610 --> 00:00:58,760 is going to be the value that's passed in for d OK? 20 00:00:58,760 --> 00:01:00,910 And also notice that inside init, I 21 00:01:00,910 --> 00:01:03,550 can do any other sort of initializations that I'd like. 22 00:01:03,550 --> 00:01:07,240 So it's not just assigning variables from the parameters 23 00:01:07,240 --> 00:01:11,720 to variables for my objects. 24 00:01:11,720 --> 00:01:14,830 So in this case I'm creating a new data attribute named 25 00:01:14,830 --> 00:01:16,630 "color," and I'm going to just create 26 00:01:16,630 --> 00:01:20,950 it to be an empty string OK, even though I didn't 27 00:01:20,950 --> 00:01:24,377 pass in any color to my object. 28 00:01:24,377 --> 00:01:26,710 So the question says, "Using the class definition above, 29 00:01:26,710 --> 00:01:28,330 which line creates a new Car object 30 00:01:28,330 --> 00:01:29,930 with 4 wheels and 2 doors?" 31 00:01:29,930 --> 00:01:31,180 OK? 32 00:01:31,180 --> 00:01:39,410 So this first one is not right, because it's 33 00:01:39,410 --> 00:01:45,920 trying to call the class with a variable mycar for self, 34 00:01:45,920 --> 00:01:47,760 which isn't quite right. 35 00:01:47,760 --> 00:01:49,970 So when you're creating your object, 36 00:01:49,970 --> 00:01:53,765 you have to give it one less parameter than what you have. 37 00:01:53,765 --> 00:01:55,640 So here we're just going to have to create it 38 00:01:55,640 --> 00:01:58,624 with the w and the d. 39 00:01:58,624 --> 00:02:04,020 So we're going to create this variable mycar 40 00:02:04,020 --> 00:02:08,400 and we're going to assign it 4 for the number of wheels and 2 41 00:02:08,400 --> 00:02:09,870 for the number of doors. 42 00:02:09,870 --> 00:02:11,910 And the number of wheels is the first parameter, 43 00:02:11,910 --> 00:02:14,010 and the number of doors is the second one, 44 00:02:14,010 --> 00:02:17,880 so it should be this one here-- Car 4 comma 2. 45 00:02:17,880 --> 00:02:19,170 So that's this one. 46 00:02:19,170 --> 00:02:20,720 Perfect.