WEBVTT

00:00:00.790 --> 00:00:03.190
The following content is
provided under a Creative

00:00:03.190 --> 00:00:04.730
Commons license.

00:00:04.730 --> 00:00:07.030
Your support will help
MIT OpenCourseWare

00:00:07.030 --> 00:00:11.390
continue to offer high-quality
educational resources for free.

00:00:11.390 --> 00:00:13.990
To make a donation or
view additional materials

00:00:13.990 --> 00:00:17.880
from hundreds of MIT courses,
visit MIT OpenCourseWare

00:00:17.880 --> 00:00:18.840
at ocw.mit.edu.

00:00:23.160 --> 00:00:26.180
ANA BELL: So we're given
this definition for car.

00:00:26.180 --> 00:00:27.750
We saw that on the
previous slide.

00:00:30.790 --> 00:00:34.300
I want to add a
method that's going

00:00:34.300 --> 00:00:38.650
to change the color of the car,
and these are my four choices.

00:00:38.650 --> 00:00:40.990
And it looks like you
guys are getting it

00:00:40.990 --> 00:00:43.296
right, which is awesome.

00:00:43.296 --> 00:00:45.670
So to find a method to change
the color of the car, which

00:00:45.670 --> 00:00:47.110
does this.

00:00:47.110 --> 00:00:51.530
So we know that self has
to be the first parameter,

00:00:51.530 --> 00:00:53.880
so we can automatically
eliminate A and C

00:00:53.880 --> 00:00:59.214
and it's between B
and D. And remember

00:00:59.214 --> 00:01:01.630
I said you have to be conscious
about whose data attribute

00:01:01.630 --> 00:01:03.590
you're accessing,
and in this case,

00:01:03.590 --> 00:01:07.150
we want to change the color of a
particular instance of the car,

00:01:07.150 --> 00:01:07.840
right?

00:01:07.840 --> 00:01:12.500
So we have to say self.color
instead of just color.

00:01:12.500 --> 00:01:14.600
If we just said
color, then color

00:01:14.600 --> 00:01:20.430
would refer to just a
variable inside the class,

00:01:20.430 --> 00:01:24.950
not a data attribute
of a particular object.