1 00:00:11,490 --> 00:00:12,940 Hi, everybody, and welcome. 2 00:00:12,970 --> 00:00:19,410 I'm super excited to continue teaching object oriented programming, as in my personal opinion, this 3 00:00:19,410 --> 00:00:23,160 is the most interesting and most useful topic in the whole course. 4 00:00:24,840 --> 00:00:31,170 OK, so it doesn't matter if you're planning to become a front end developer or a back end developer 5 00:00:31,200 --> 00:00:38,160 or an automation developer, if you're going to use Python in your work, you must dominate the old 6 00:00:38,460 --> 00:00:39,060 topic. 7 00:00:40,740 --> 00:00:48,150 If you recall from the previous video, we have set up a number of goals, a number of topics to study, 8 00:00:48,150 --> 00:00:50,190 and we have studied part of them. 9 00:00:51,450 --> 00:00:53,000 Let's have a quick overview. 10 00:00:53,040 --> 00:00:53,420 All right. 11 00:00:53,850 --> 00:00:57,380 First of all, we have seen the hierarchy inside by charm. 12 00:00:57,690 --> 00:01:03,900 We have seen what a module, class method and variable right afterwards. 13 00:01:03,910 --> 00:01:11,790 We have learned how to create a simple class, in our case, core class, which has a simple variable 14 00:01:11,790 --> 00:01:13,530 and a single print action. 15 00:01:14,670 --> 00:01:19,980 Then with the help of this class, we have also tried to create an instance of an object. 16 00:01:19,980 --> 00:01:23,130 We have two of them, Aldy, a three and four focus. 17 00:01:24,510 --> 00:01:33,060 These topics bring us halfway, but we need to add some more knowledge in order to create professional 18 00:01:33,060 --> 00:01:38,640 objects that could be very useful in our programming in the future and in the present as well. 19 00:01:39,540 --> 00:01:46,860 So usually I know that I'm starting off explaining the terminal terminology, but today I think will 20 00:01:46,860 --> 00:01:49,730 begin off from a simple example. 21 00:01:50,580 --> 00:01:54,370 This example will conclude all of these three parts as well. 22 00:01:54,600 --> 00:01:56,140 Let's go over them quickly. 23 00:01:57,480 --> 00:02:02,890 First of all, we'll learn what our properties are an object and we will cover the function. 24 00:02:03,450 --> 00:02:10,830 We will also study how to use the self parameter of a property and we're going to cover objects methods. 25 00:02:11,970 --> 00:02:17,700 So let's dive deep into this example and go from the top. 26 00:02:18,240 --> 00:02:21,140 Just follow my lead and everything's going to be just fine. 27 00:02:21,360 --> 00:02:26,550 It's not too complicated once you break down these topics into small bricks. 28 00:02:28,250 --> 00:02:35,880 So we have created a class here class, his name is employee, and this class contains three methods. 29 00:02:36,290 --> 00:02:39,430 OK, the first method is death, OK? 30 00:02:39,450 --> 00:02:46,300 And we know that all of these are methods because the def keyword indicates that this is a method. 31 00:02:46,310 --> 00:02:46,730 All right. 32 00:02:47,750 --> 00:02:53,390 And we can see here like a new type of method that we haven't seen before. 33 00:02:54,230 --> 00:03:00,710 The method has underscore then in it and then additional underscore, OK, we haven't encountered this 34 00:03:00,710 --> 00:03:03,320 method or these type of methods before. 35 00:03:03,590 --> 00:03:06,610 And that's because it's a reserved method. 36 00:03:06,620 --> 00:03:14,780 It's a special method that PI charm who invented by charm, made it this this way that this method can't 37 00:03:14,780 --> 00:03:20,080 be used in any different way but inside the objects. 38 00:03:20,530 --> 00:03:28,180 OK, we will ignore this method for the next minute and we will get back to it afterwards. 39 00:03:28,700 --> 00:03:35,450 So we have here two simple methods attendance, attendance, check and show employees details and we 40 00:03:35,450 --> 00:03:37,490 have a certain point action inside them. 41 00:03:38,060 --> 00:03:41,840 But I want to focus on this bottom part right here. 42 00:03:42,280 --> 00:03:46,060 OK, we have two instances here. 43 00:03:46,100 --> 00:03:53,450 OK, you can see it's an instance because we have a name that we picked Sarah and Michael, and then 44 00:03:53,450 --> 00:03:58,490 we have the equals equals sign and then we mention the name of the class. 45 00:03:59,030 --> 00:04:04,180 OK, so this is exactly what we did in the previous video, right? 46 00:04:04,550 --> 00:04:09,080 We have set a name then both equals and then we have the name of the class. 47 00:04:09,500 --> 00:04:19,130 But in this case, we haven't passed any variables inside the class while here we're passing variables 48 00:04:19,130 --> 00:04:22,960 inside these brackets that will be passed into the class. 49 00:04:23,180 --> 00:04:23,650 Correct. 50 00:04:25,780 --> 00:04:33,610 OK, so we have here two instances of an object and let's go over them and see the flow of the code 51 00:04:33,610 --> 00:04:34,960 and what's going on over here. 52 00:04:35,260 --> 00:04:41,980 And obviously, these five last lines are outside of the class as everything's inside. 53 00:04:41,980 --> 00:04:47,920 The class is with indention, with spaces, while everything here is without indention. 54 00:04:47,950 --> 00:04:49,870 So this is outside of the class. 55 00:04:50,170 --> 00:04:54,940 And these are objects instances that we're going to explain right now. 56 00:04:56,590 --> 00:05:03,970 Jumping for one last time up in here, we can also hear see here that the three and four focus also 57 00:05:03,970 --> 00:05:08,410 does not have indention once we compare it to the class indention level. 58 00:05:08,590 --> 00:05:11,370 So these two are outside of the class as well. 59 00:05:13,120 --> 00:05:21,370 All right, so if we take this Michael Instant's right here, we can see his type is he's an employee, 60 00:05:21,380 --> 00:05:21,780 OK? 61 00:05:21,910 --> 00:05:27,090 Michael is an employee, his type is employee. 62 00:05:27,370 --> 00:05:33,850 OK, it doesn't go we're not going to go into details what that means right now. 63 00:05:34,090 --> 00:05:43,210 But what we need to know now is that we have created an instance, which is name is Michael and Michael 64 00:05:43,210 --> 00:05:44,320 is an employee. 65 00:05:44,350 --> 00:05:52,720 OK, just imagine to yourself that we have a program here, often of an office manager of some office, 66 00:05:52,720 --> 00:05:53,160 OK? 67 00:05:53,470 --> 00:06:01,840 And she has this program that she must feel employees details their each new employee comes to her and 68 00:06:01,840 --> 00:06:05,410 she needs to fill these details for each and every one of them. 69 00:06:05,830 --> 00:06:08,800 OK, so this is what she will do. 70 00:06:08,840 --> 00:06:09,230 OK. 71 00:06:09,430 --> 00:06:17,710 She would ask each employee what's what is his name, what the salary that he's making, even that they're 72 00:06:17,720 --> 00:06:18,960 basically illegal. 73 00:06:19,510 --> 00:06:19,990 All right. 74 00:06:20,350 --> 00:06:21,580 But let's go with it. 75 00:06:22,090 --> 00:06:27,940 And then she would ask him whether he was being at work for the last week. 76 00:06:28,310 --> 00:06:33,030 OK, just like invent something, just trying to improvise here, OK? 77 00:06:33,310 --> 00:06:40,480 So she must she must ask each of the each of the employees these three questions and she needs to get 78 00:06:40,480 --> 00:06:41,450 data from them. 79 00:06:41,480 --> 00:06:49,270 OK, so Michael, obviously this is the name of the instance, OK, but here are the questions that 80 00:06:49,540 --> 00:06:50,710 he's going to be asked. 81 00:06:50,950 --> 00:06:51,730 What's your name. 82 00:06:51,850 --> 00:06:52,480 Michael. 83 00:06:52,750 --> 00:06:53,890 How much do you make? 84 00:06:54,040 --> 00:06:54,930 Three thousand. 85 00:06:55,060 --> 00:06:58,700 And did you, uh, did you attend to work all the last week? 86 00:06:58,720 --> 00:06:59,710 True or false? 87 00:07:00,010 --> 00:07:03,540 OK, so you can see the number one here. 88 00:07:04,180 --> 00:07:07,800 So this Michael variable starts off here. 89 00:07:07,810 --> 00:07:10,450 OK, so here's the instance of an object. 90 00:07:10,570 --> 00:07:14,230 And after we write it down here, it's going to go. 91 00:07:14,230 --> 00:07:19,240 The following flow from here is going to get up to the top. 92 00:07:19,570 --> 00:07:25,360 And inside this init method, this init method is called the constructor. 93 00:07:26,720 --> 00:07:34,150 A constructor basically builds up an employee in our case inside the program. 94 00:07:34,180 --> 00:07:41,980 OK, so it receives these three variables name, salary and attendance from each of these instances 95 00:07:41,980 --> 00:07:43,000 separately. 96 00:07:43,180 --> 00:07:46,030 OK, so we're going to discuss Michael first. 97 00:07:46,330 --> 00:07:53,350 So it receives these three variables from Michael name, salary and attendance and obviously from the 98 00:07:53,350 --> 00:07:59,530 top here from the method declaration goes the name goes inside here because it's the same thing which 99 00:07:59,530 --> 00:08:00,620 is using it here. 100 00:08:00,910 --> 00:08:02,080 Here's the declaration. 101 00:08:02,080 --> 00:08:07,120 And here we use it goes in here, salary and attendance. 102 00:08:07,160 --> 00:08:13,300 OK, and from this right part is going it's going to the self name. 103 00:08:13,450 --> 00:08:18,590 Self name is the property of these instances. 104 00:08:18,610 --> 00:08:22,750 OK, self name is a property of Michael. 105 00:08:24,160 --> 00:08:26,670 So we are having Michael variable here. 106 00:08:27,550 --> 00:08:29,500 It's basically the same thing as we're doing. 107 00:08:29,860 --> 00:08:34,840 For example, X equals five plus X equals five plus one. 108 00:08:35,880 --> 00:08:40,330 OK, so whatever is at the right goes inside to what's in the left. 109 00:08:40,450 --> 00:08:49,630 OK, so the name is Michael and it goes straight into this bar, the left bar here, self name, self 110 00:08:49,630 --> 00:08:59,740 name is called a property of an object and it is stored somewhere in the memory of the computer. 111 00:08:59,770 --> 00:09:02,370 As long as your code is running. 112 00:09:02,950 --> 00:09:08,560 What that means is that as long as we have said as we have clicked right. 113 00:09:08,560 --> 00:09:12,430 Click on the file and clicked run as long as this will run. 114 00:09:13,000 --> 00:09:17,100 Once we passed this line right here, Michael equals employee. 115 00:09:17,620 --> 00:09:27,460 These variables would be stored somewhere in the memory, somewhere, the memory for our future usage. 116 00:09:27,940 --> 00:09:36,310 OK, and we also have Sarah, OK, this is the instance of Sarah, the office manager, ask her the 117 00:09:36,310 --> 00:09:37,240 same questions. 118 00:09:37,510 --> 00:09:46,150 So the first user name, salary and a tendency and these three variables where it went again up in here 119 00:09:46,160 --> 00:09:49,000 inside of def name, salary and attendance. 120 00:09:49,930 --> 00:09:53,380 And then from here they went to here, here and here. 121 00:09:53,590 --> 00:09:59,740 And then they went inside the self parameter, the self parameter, which is the property. 122 00:10:00,100 --> 00:10:04,840 And also Sarah's details are stored in the memory as well. 123 00:10:05,650 --> 00:10:11,890 OK, and now once we passed this part, once we passed the instance by the. 124 00:10:11,980 --> 00:10:13,680 Creation of an instant sport. 125 00:10:13,710 --> 00:10:22,770 OK, now we can do stuff with these with these properties, OK, we can apply manipulation on them, 126 00:10:22,980 --> 00:10:25,080 we can print them, we can do anything. 127 00:10:25,890 --> 00:10:35,190 OK, so from these parameters, from these properties here, they can be used inside every method which 128 00:10:35,190 --> 00:10:36,710 is inside this class. 129 00:10:37,030 --> 00:10:43,950 OK, so from here, from the cell number three, we can use these variables inside the methods. 130 00:10:44,460 --> 00:10:55,110 OK, so if we're talking about Michael and we want to show employee details, for example, we want 131 00:10:55,110 --> 00:10:56,940 to use this method, OK? 132 00:10:58,080 --> 00:11:00,050 We want to use this method and this method. 133 00:11:00,060 --> 00:11:06,000 What it does is it brings the string name and then OK. 134 00:11:06,060 --> 00:11:10,060 And then it prints self dot name, OK. 135 00:11:10,350 --> 00:11:16,110 In Michael's case, the name, which is the first variable here and the first here, and the name is 136 00:11:16,110 --> 00:11:17,380 Michael as a string. 137 00:11:17,850 --> 00:11:25,650 So what we'll get here is name to Dot Michael and then salary two dots and then self salary. 138 00:11:25,770 --> 00:11:26,790 Self salary. 139 00:11:27,060 --> 00:11:34,710 You can see here the second variable and also here is the second it will get the number three thousand, 140 00:11:34,710 --> 00:11:34,990 OK? 141 00:11:35,010 --> 00:11:39,600 It goes from here to here to here. 142 00:11:40,960 --> 00:11:46,960 And then to hear, OK, this is the flow, I specifically roll down the numbers so it will be easy to 143 00:11:46,960 --> 00:11:49,620 keep track of the data flow. 144 00:11:50,640 --> 00:11:52,540 OK, and this is basically it. 145 00:11:53,680 --> 00:12:00,850 And then once we want to show employee details of Sarah, OK, we're going to do the same thing, like 146 00:12:00,850 --> 00:12:06,910 we're going to put Sarah Dot and then then the name of the method. 147 00:12:07,240 --> 00:12:11,450 We're calling out the method with Sarah's properties. 148 00:12:11,470 --> 00:12:12,460 This is what we're doing. 149 00:12:12,730 --> 00:12:18,940 We're not writing employee dot show employee details because we won't have any properties. 150 00:12:19,060 --> 00:12:20,200 We created Sarah. 151 00:12:20,950 --> 00:12:27,100 We have set variables into her and now we can using this method with her properties. 152 00:12:27,640 --> 00:12:28,150 OK. 153 00:12:29,550 --> 00:12:31,560 So this is basically it. 154 00:12:33,210 --> 00:12:40,470 I think we have covered all of this, all of these parts pretty much deeply as much as we can. 155 00:12:41,860 --> 00:12:48,840 And now let's go to explaining these terms in much more clear way. 156 00:12:48,980 --> 00:12:55,370 Is a text OK, visual explanation in helpful of a tax explanation. 157 00:12:55,950 --> 00:12:57,960 So we have created an employee class. 158 00:12:58,410 --> 00:13:04,490 OK, that class represents a standard employee in a certain company. 159 00:13:05,400 --> 00:13:08,310 Each employee must have the following properties. 160 00:13:08,310 --> 00:13:09,300 He must have them. 161 00:13:09,630 --> 00:13:15,020 Each employee that we creating, for example, we have Sarah, which is employee Michael employee. 162 00:13:15,300 --> 00:13:20,210 Each of these employees must contain name, salary and attendance status. 163 00:13:21,600 --> 00:13:24,030 We have created to object instances. 164 00:13:24,190 --> 00:13:25,230 OK, Sarah. 165 00:13:32,690 --> 00:13:33,380 Like this. 166 00:13:33,730 --> 00:13:43,040 OK, Sarah and Michael, and we have set these variables inside each of them, OK, then variables are 167 00:13:43,040 --> 00:13:47,660 passed to each instance, employee's name, salary and attendance. 168 00:13:47,870 --> 00:13:54,860 These variables would be collected by the in its special method and stored for each instance. 169 00:13:55,060 --> 00:13:57,890 OK, so the Init method collects them and stores them. 170 00:14:00,900 --> 00:14:09,300 Then the deaf init method receives the variables from the object instances and then converts them into 171 00:14:09,300 --> 00:14:10,840 property of an object. 172 00:14:11,970 --> 00:14:13,130 This happens right here. 173 00:14:13,140 --> 00:14:21,420 We have the variable and it is converted that converted equalized to the property of the instance. 174 00:14:24,640 --> 00:14:32,410 Then the properties, these properties which are saved, are used whenever any method is called by an 175 00:14:32,410 --> 00:14:33,610 object instance. 176 00:14:33,680 --> 00:14:40,360 OK, so once you want to call a certain method, for example, show employee details, it's called out 177 00:14:40,360 --> 00:14:44,320 by the name of the instance instance name DOT Method. 178 00:14:46,280 --> 00:14:49,310 All right, and that's about it. 179 00:14:49,470 --> 00:14:57,620 OK, I saw you go back to the cold example and review the flow of the variable using the marker marked. 180 00:14:57,620 --> 00:15:00,390 No, but we already did it. 181 00:15:00,460 --> 00:15:05,900 OK, the variable is inserted into the instance. 182 00:15:06,290 --> 00:15:12,620 Then it goes up in here to the in it and then from the unit, it goes inside the unit and then it can 183 00:15:12,620 --> 00:15:15,620 be used in every method inside the class. 184 00:15:17,510 --> 00:15:23,450 I really thought that it would be very useful to show a live good example of what we just seen. 185 00:15:23,660 --> 00:15:33,980 OK, so we have Sarah incents Michael Instant's sorry, Sarah and Michael and we have these methods 186 00:15:34,190 --> 00:15:34,830 printed out. 187 00:15:34,880 --> 00:15:36,260 OK, so let's just run it. 188 00:15:40,500 --> 00:15:43,760 There you go, so what's what are these all these prints? 189 00:15:45,060 --> 00:15:47,670 First of all, we have you know what? 190 00:15:47,920 --> 00:15:51,720 Let me just remove this so we won't get confused. 191 00:15:51,750 --> 00:15:52,080 All right. 192 00:15:53,660 --> 00:16:00,620 So right now, we have just have this, Sarah, incidents that we have created and out of it we want 193 00:16:00,620 --> 00:16:07,510 to print out, we want to execute actually the show employee details method, OK, this is this method. 194 00:16:08,180 --> 00:16:14,240 So we have inserted this variable O as first, this one a second, this method. 195 00:16:14,690 --> 00:16:24,230 And from here, OK, they are passed up to the in it and from here the name goes up in here and then 196 00:16:24,230 --> 00:16:28,520 this property is used in each of these methods. 197 00:16:28,520 --> 00:16:31,480 You can see when I marked it and it's marked right here as well. 198 00:16:31,880 --> 00:16:33,320 So just pass the inside. 199 00:16:34,490 --> 00:16:39,350 And the name is unique for each of these instances here. 200 00:16:39,360 --> 00:16:40,640 The name is Sarah here. 201 00:16:40,640 --> 00:16:41,510 The name is Michael. 202 00:16:41,990 --> 00:16:45,260 So I wanted to print out Sarah's. 203 00:16:46,650 --> 00:16:47,890 Details, OK? 204 00:16:48,240 --> 00:16:52,020 The name of the instance that the method. 205 00:16:52,060 --> 00:16:56,130 OK, so once we do that, we simply get. 206 00:16:57,270 --> 00:16:57,780 Name. 207 00:16:58,950 --> 00:17:01,720 OK, then we have Silvani, which is Sarah's name. 208 00:17:02,550 --> 00:17:03,030 All right. 209 00:17:04,610 --> 00:17:12,080 And then we have the celery and selfs celery, but what is this self celery, the self celery is self 210 00:17:12,200 --> 00:17:17,540 that got from here, that goes from here, here and here. 211 00:17:17,720 --> 00:17:22,550 OK, so this is what will be printed out and same goes for Michael. 212 00:17:23,660 --> 00:17:26,150 OK, so if we do the same thing for Michael. 213 00:17:32,380 --> 00:17:38,980 We'll get his details as well and just we have here another are another matter. 214 00:17:38,990 --> 00:17:40,090 Let's try to print it. 215 00:17:40,980 --> 00:17:44,170 I'm going to do Michael Dott attendance check. 216 00:17:44,650 --> 00:17:46,090 OK, same thing. 217 00:17:46,090 --> 00:17:55,150 Michael's properties go inside this method and we have here his name and then like s attendance status 218 00:17:55,150 --> 00:17:55,570 is. 219 00:17:55,780 --> 00:17:58,820 And then we converted the attendance again. 220 00:17:58,840 --> 00:18:00,410 Why did we do it? 221 00:18:00,430 --> 00:18:03,400 It's casting because it's a boolean, right? 222 00:18:03,760 --> 00:18:04,740 The attendance. 223 00:18:04,750 --> 00:18:05,380 This one. 224 00:18:05,890 --> 00:18:06,520 This one. 225 00:18:07,060 --> 00:18:07,810 This one. 226 00:18:08,230 --> 00:18:10,570 And this one is a boolean. 227 00:18:10,600 --> 00:18:15,130 OK, and here we're printing out strings, so we need to do the casting. 228 00:18:16,560 --> 00:18:22,550 So we wanting to print out the attendance check of Michael, let's do it and see what happens. 229 00:18:23,780 --> 00:18:26,060 There you go, Michael, sit down. 230 00:18:26,120 --> 00:18:27,350 This is true. 231 00:18:27,600 --> 00:18:35,150 OK, and you can see that this variable passed through all these baths and went up on here, OK, and 232 00:18:35,150 --> 00:18:39,920 then we do this the following thing for as well, OK? 233 00:18:46,390 --> 00:18:53,500 You can see Sarah's attendance is false, and that's because this is this false boolean variable appears 234 00:18:53,500 --> 00:18:54,080 up here. 235 00:18:55,090 --> 00:18:55,610 All right. 236 00:18:55,630 --> 00:18:59,080 So I'm very happy that we have covered all of these topics. 237 00:18:59,770 --> 00:19:04,930 Basically, now we can do whatever we want using all of these parts. 238 00:19:04,930 --> 00:19:06,910 So we have the instance of an object. 239 00:19:07,120 --> 00:19:08,650 We have the init method. 240 00:19:09,370 --> 00:19:14,320 We have the self parameter, and we have classes, methods. 241 00:19:14,530 --> 00:19:16,330 We know how to use all of them. 242 00:19:16,990 --> 00:19:24,550 And in the next lectures, we'll have some challenging assignments and we'll try to use them in a more 243 00:19:24,550 --> 00:19:25,510 complex way. 244 00:19:25,780 --> 00:19:31,840 After seeing a live called example and the next lecture, I think you'll be ready to do some training. 245 00:19:32,440 --> 00:19:36,940 And also a special project is waiting for you like a mega assignment. 246 00:19:37,210 --> 00:19:43,420 But don't worry, I'm just trying to make you stronger and make you dominators in object oriented programming. 247 00:19:43,600 --> 00:19:44,170 Thank you. 248 00:19:44,170 --> 00:19:45,670 And we'll see you in the next lecture.