1 00:00:08,000 --> 00:00:11,985 Welcome back. So, in this piece of code. 2 00:00:11,985 --> 00:00:18,120 Here we set the instance variable for x for both point one and point two on lines 89. 3 00:00:18,120 --> 00:00:20,930 Now, even though you can do this in your pipeline code, 4 00:00:20,930 --> 00:00:23,955 this isn't the way that you should set instance variables. 5 00:00:23,955 --> 00:00:29,680 So, instead you should set instance variables in what's called a constructor. 6 00:00:30,710 --> 00:00:35,090 Now, a constructor is a special method that's meant to 7 00:00:35,090 --> 00:00:39,890 initialize Python instances, including instance variables. 8 00:00:39,890 --> 00:00:43,880 So, the constructor is named what's called 9 00:00:43,880 --> 00:00:48,900 underscore underscore init underscore underscore. 10 00:00:48,900 --> 00:00:51,825 It's just a special method with this name 11 00:00:51,825 --> 00:00:55,620 underscore underscore init underscore underscore. 12 00:00:55,620 --> 00:00:58,700 Now, I'm going to call this instead 13 00:00:58,700 --> 00:01:02,370 of underscore underscore I'm going to say dunderscore. 14 00:01:03,370 --> 00:01:08,160 So, that we'd make this dunderscore init dunderscore. 15 00:01:08,160 --> 00:01:11,025 But instead of saying dunderscore init dunderscore. 16 00:01:11,025 --> 00:01:15,075 I'm just going to say dunderscore init for now. 17 00:01:15,075 --> 00:01:19,535 So, we want to define our constructor dunderscore init. 18 00:01:19,535 --> 00:01:26,855 So, the way that we do that is we define this method and we can say def 19 00:01:26,855 --> 00:01:32,360 dunderscore init dunderscore and init 20 00:01:32,360 --> 00:01:37,860 just like every other method takes in self as its first argument. 21 00:01:37,860 --> 00:01:42,875 I'm going to pass in two more arguments x and y. 22 00:01:42,875 --> 00:01:45,560 Now, in our constructor, 23 00:01:45,560 --> 00:01:49,085 I'm going to say self.x equals x, 24 00:01:49,085 --> 00:01:52,875 and self.y equals y. 25 00:01:52,875 --> 00:01:58,010 Now, if I delete these lines and try to run my code as this. 26 00:01:58,010 --> 00:02:00,160 Then I'm going to get a run-time error, 27 00:02:00,160 --> 00:02:02,660 saying that my constructor method takes 28 00:02:02,660 --> 00:02:06,560 exactly three arguments but only one was given on line nine. 29 00:02:06,560 --> 00:02:08,750 What that's saying is that, 30 00:02:08,750 --> 00:02:13,715 so it takes three arguments but self was already provided when we called our constructor. 31 00:02:13,715 --> 00:02:19,305 We need to pass in values for x and y as soon as we create instances of point. 32 00:02:19,305 --> 00:02:25,085 So, here I'm going to pass in values five and 10 for this point, 33 00:02:25,085 --> 00:02:29,840 and one and two for point two. 34 00:02:29,840 --> 00:02:34,145 Now what happens here is that for point one, 35 00:02:34,145 --> 00:02:38,180 I'm passing five in for x and 10 in for y. 36 00:02:38,180 --> 00:02:45,600 For point two, I'm passing one in for x and two in for y. 37 00:02:45,820 --> 00:02:49,760 Rather than setting the instance variables later on, 38 00:02:49,760 --> 00:02:53,755 then what we're doing is we're setting the instance variables in this constructor. 39 00:02:53,755 --> 00:02:57,840 So, when we say self.x equals x for point one, 40 00:02:57,840 --> 00:03:05,385 that's setting point one.x to be five and point one.y to be 10. 41 00:03:05,385 --> 00:03:15,180 When we do this for point two then we're setting point two.x to be point two.y to be two. 42 00:03:15,180 --> 00:03:19,425 So, now if I call get x on point one, 43 00:03:19,425 --> 00:03:24,580 so print point one.get x. 44 00:03:24,710 --> 00:03:27,110 Then I should get five. 45 00:03:27,110 --> 00:03:29,975 If I print out point two.get x, 46 00:03:29,975 --> 00:03:31,880 then I should get one. 47 00:03:31,880 --> 00:03:35,310 That's all for now until next time.