1 00:00:11,920 --> 00:00:13,020 Hi, everybody. 2 00:00:13,260 --> 00:00:19,900 I'm so happy that you're here with me, and today we're going to discuss further regarding object oriented 3 00:00:19,900 --> 00:00:21,190 programming in Python. 4 00:00:22,570 --> 00:00:29,950 In the previous video, we have seen an overview of what is an object and how can we create instances 5 00:00:29,950 --> 00:00:30,790 of an object. 6 00:00:31,420 --> 00:00:33,610 We had like a sketch of a car. 7 00:00:33,790 --> 00:00:36,880 And on top of that, we could create two types. 8 00:00:36,880 --> 00:00:39,970 Of course, this was only an overview look. 9 00:00:39,970 --> 00:00:49,180 And today we will start explaining each term before getting to the point where we can create actual 10 00:00:49,180 --> 00:00:51,580 objects like advanced objects. 11 00:00:51,590 --> 00:00:56,650 We will start explaining everything from zero from this lecture right now. 12 00:00:57,910 --> 00:01:04,300 And let's go over the list of terms that we are going to discuss in this lecture and also in the following 13 00:01:04,300 --> 00:01:05,250 lectures as well. 14 00:01:06,040 --> 00:01:07,690 So what's in our menu? 15 00:01:09,310 --> 00:01:11,980 What is a class and how to create one? 16 00:01:11,990 --> 00:01:18,400 We will discuss it in a few seconds right here below how to create an actual object. 17 00:01:19,660 --> 00:01:28,000 And then we'll learn what our properties of an object we will use a special method and also a special 18 00:01:28,000 --> 00:01:31,290 type of method that we haven't seen before called in it. 19 00:01:31,600 --> 00:01:36,790 OK, so look down to this thing as well and then we will talk. 20 00:01:36,790 --> 00:01:39,840 What is a self parameter of a property? 21 00:01:40,570 --> 00:01:41,900 These two are connected. 22 00:01:42,940 --> 00:01:48,660 Don't worry if it sounds a bit scary because as you know, you don't need any prior knowledge. 23 00:01:48,680 --> 00:01:49,360 Do all this. 24 00:01:49,660 --> 00:01:51,980 We're going to discuss it from zero. 25 00:01:52,050 --> 00:01:58,760 OK, and then we will learn what our object methods and how to use them. 26 00:01:59,130 --> 00:02:09,010 OK, also, after we'll explain all of these terms, we'll start building the car object that we have 27 00:02:09,010 --> 00:02:14,290 seen in previous lecture from zero in live coding examples as always. 28 00:02:15,790 --> 00:02:23,740 All right, so first of all, let's start with the third with the first bullet classes, OK, so what 29 00:02:23,740 --> 00:02:25,270 are classis? 30 00:02:25,510 --> 00:02:31,840 So we are all very familiar of how to declaring method's OK. 31 00:02:32,050 --> 00:02:38,140 So once we want to declare a method, we just use the Def Keywood and then afterwards we put the name 32 00:02:38,140 --> 00:02:38,920 of the method. 33 00:02:39,130 --> 00:02:49,600 Small letters underscores between each each word as the coding convention tells us. 34 00:02:49,630 --> 00:02:56,590 OK, so a class declaration happening in the very similar way, but this time we will have to use a 35 00:02:56,590 --> 00:03:00,010 Klasky word and then give the name of the class. 36 00:03:00,160 --> 00:03:00,610 All right. 37 00:03:02,440 --> 00:03:11,560 So this is how we create classes, but where classes fit in, in the hierarchy of PyCon, meaning, 38 00:03:12,100 --> 00:03:14,320 for example, we know that our methods. 39 00:03:14,480 --> 00:03:14,920 All right. 40 00:03:15,160 --> 00:03:22,780 And we can contain variables inside these methods and we can also manipulate variables inside these 41 00:03:22,780 --> 00:03:23,200 methods. 42 00:03:23,380 --> 00:03:27,460 But we know that a variable is inside a method. 43 00:03:27,490 --> 00:03:30,600 OK, so method contains a variable. 44 00:03:30,610 --> 00:03:31,810 It can contain a variable. 45 00:03:32,170 --> 00:03:34,700 But where classes come in all this picture. 46 00:03:35,560 --> 00:03:42,310 So let's go over the whole hierarchy of all entities and see who is the parent of who. 47 00:03:43,090 --> 00:03:44,230 It's very, very simple. 48 00:03:44,350 --> 00:03:44,710 All right. 49 00:03:45,310 --> 00:03:52,180 So first of all, here in the bottom left, we have in the screenshot we have a file called Filed by. 50 00:03:52,300 --> 00:03:55,750 OK, so the file of Python called a module. 51 00:03:56,200 --> 00:03:59,610 This is the official name of a file entity. 52 00:03:59,620 --> 00:04:00,650 It's called a module. 53 00:04:00,700 --> 00:04:07,240 OK, and then beneath it, OK, beneath it. 54 00:04:07,750 --> 00:04:15,520 Meaning in the hierarchy, inside inside this file, you can see here at the top as the first hierarchy 55 00:04:15,520 --> 00:04:18,020 inside a module is a class. 56 00:04:18,050 --> 00:04:26,100 OK, you can see here the class keyword colored in orange and then you can see this is my class. 57 00:04:26,140 --> 00:04:28,120 OK, this is the name of the class. 58 00:04:28,120 --> 00:04:35,100 And then to come afterwards, we will also discuss naming conventions between classes. 59 00:04:35,110 --> 00:04:38,200 You can see it's not written with small letters and the scores. 60 00:04:38,230 --> 00:04:38,590 All right. 61 00:04:38,590 --> 00:04:40,110 We'll talk about it in a few minutes. 62 00:04:40,510 --> 00:04:44,620 But the fact that I want you to notice here that class is the top hierarchy. 63 00:04:44,860 --> 00:04:47,570 Then you have some indention and you have a method. 64 00:04:47,620 --> 00:04:50,590 OK, and then you have some more indention and you have this. 65 00:04:50,740 --> 00:04:52,600 This is my variable equals five. 66 00:04:53,490 --> 00:04:59,720 OK, so class either is the parent of a method and method is the parent of a variable. 67 00:04:59,740 --> 00:05:00,690 This is how it works. 68 00:05:00,750 --> 00:05:01,060 Right. 69 00:05:02,470 --> 00:05:07,450 And just have a quick reminder regarding coding conventions. 70 00:05:07,720 --> 00:05:09,160 We always discuss that. 71 00:05:09,400 --> 00:05:12,550 I want you to become a professional developers and not rookies. 72 00:05:12,730 --> 00:05:19,090 And for that, each professional developer which will look at your code, you'd notice if you a pro 73 00:05:19,090 --> 00:05:24,300 or not, simply by the naming of your entities inside your code. 74 00:05:24,700 --> 00:05:32,860 So I have to mention that classes goes with capital letters in all of the words and without underscores 75 00:05:32,890 --> 00:05:33,760 between the words. 76 00:05:33,760 --> 00:05:35,280 So you can see an example. 77 00:05:35,650 --> 00:05:37,810 This is my class right here. 78 00:05:38,790 --> 00:05:43,410 So this is the coding in the naming coding convention for Python classes. 79 00:05:43,450 --> 00:05:45,560 This is the official way to call classes. 80 00:05:46,960 --> 00:05:53,020 OK, so concluding the whole this whole session, we have a file which called a module, and then you 81 00:05:53,020 --> 00:05:58,600 have a class that is the top hierarchy inside a module and beneath it you have the method and then you 82 00:05:58,600 --> 00:05:59,410 have a variable. 83 00:05:59,620 --> 00:06:00,010 All right. 84 00:06:01,000 --> 00:06:02,590 Let's go further down the road. 85 00:06:02,750 --> 00:06:07,960 OK, so now we already seen here a creation of class, by the way. 86 00:06:07,960 --> 00:06:10,100 You even you haven't even noticed. 87 00:06:10,120 --> 00:06:12,790 OK, but now let's see how to create a class. 88 00:06:12,820 --> 00:06:13,690 What are the rules? 89 00:06:13,690 --> 00:06:15,230 What are the simple basic rules? 90 00:06:15,250 --> 00:06:18,540 OK, so let's look at this part. 91 00:06:18,550 --> 00:06:22,440 OK, so you create a class, use the keyword class. 92 00:06:22,450 --> 00:06:23,950 Obviously, we just talked about it. 93 00:06:24,460 --> 00:06:27,750 And let's see, how can we do classes declaration. 94 00:06:27,760 --> 00:06:28,070 OK. 95 00:06:28,300 --> 00:06:35,080 So once you want to declare a class, just write the class keyword and then write the name of your class 96 00:06:35,290 --> 00:06:41,540 with capital letters with no underscores between the letters and then put to dots afterwards. 97 00:06:41,560 --> 00:06:43,420 OK, so this is classic Liberacion. 98 00:06:43,840 --> 00:06:52,750 Then in this specific example you can see a variable is stored straight away under a class without any 99 00:06:52,750 --> 00:06:54,580 method inside this class at all. 100 00:06:54,630 --> 00:07:00,840 OK, and this is not a problem because here you can see the class is there like Grant. 101 00:07:01,390 --> 00:07:03,160 OK, you have two generations here. 102 00:07:04,040 --> 00:07:08,360 Class is the grandparent of these variable meaning class is on top of variable. 103 00:07:08,950 --> 00:07:12,580 So once we are not having this method here, it's OK. 104 00:07:12,580 --> 00:07:14,770 So a variable can be stored. 105 00:07:15,030 --> 00:07:18,010 Class is this is not a problem. 106 00:07:19,560 --> 00:07:23,600 OK, and you have a simple variable here, you equals two thousand. 107 00:07:23,640 --> 00:07:29,730 This is a simple variable and set a class and that we have just a simple PERENT action, by the way. 108 00:07:29,730 --> 00:07:34,520 It's an error because it's not an ear, actually, it's a car owner. 109 00:07:34,800 --> 00:07:36,510 Just fix it like that. 110 00:07:36,540 --> 00:07:36,990 All right. 111 00:07:38,830 --> 00:07:46,120 So we have here a class declaration, we have a class name, we have a variable and we have a simple 112 00:07:46,120 --> 00:07:47,410 print of that variable. 113 00:07:47,650 --> 00:07:49,160 All right, so there you go. 114 00:07:49,210 --> 00:07:55,360 We have created a simple class, not very difficult, nothing to worry about, you see, just declaration 115 00:07:55,360 --> 00:07:58,160 and then you can put stuff inside it for now. 116 00:07:58,180 --> 00:07:58,500 All right. 117 00:07:59,830 --> 00:08:08,800 So now we can use the class of car class, this class, and let's create an instance of an object or 118 00:08:08,800 --> 00:08:10,810 an instance of a class also. 119 00:08:11,200 --> 00:08:11,620 All right. 120 00:08:11,830 --> 00:08:16,700 So we have this class and we want to create an instance for it. 121 00:08:16,990 --> 00:08:25,300 So this is like the old car sketch from the previous lecture where we've seen, like, a simple old 122 00:08:25,510 --> 00:08:26,600 geraud car. 123 00:08:26,650 --> 00:08:28,600 OK, so this is it. 124 00:08:28,630 --> 00:08:32,120 And now we want to create an instances out of it. 125 00:08:32,140 --> 00:08:34,660 OK, so this is how you do it. 126 00:08:34,900 --> 00:08:35,250 All right. 127 00:08:35,740 --> 00:08:43,810 So here is the class declaration, as we have seen a few few moments ago, right here below, you can 128 00:08:43,810 --> 00:08:46,480 see an instance of an object. 129 00:08:46,510 --> 00:08:53,260 OK, so at the left part, just right the name of your instance, you can give it any name, same as 130 00:08:53,260 --> 00:08:53,770 a variable. 131 00:08:53,770 --> 00:08:56,980 Just give any name, small letters with underscores. 132 00:08:57,010 --> 00:08:57,970 OK, it's a variable. 133 00:08:59,140 --> 00:09:06,920 Then you put equals and then you put the name of the class that this instance belongs to. 134 00:09:07,090 --> 00:09:13,870 OK, the Audi underscore a three instance belongs to this car class. 135 00:09:14,200 --> 00:09:16,900 So just write the name of the class. 136 00:09:16,930 --> 00:09:27,220 OK, so we have now an Audi A3, which is an instance of car class, and we also have a Ford Focus, 137 00:09:27,550 --> 00:09:32,560 which is a second instance of an object or instance of a class. 138 00:09:32,950 --> 00:09:36,000 And it also equals two cars class meaning. 139 00:09:36,200 --> 00:09:43,930 Meaning you can imagine that you have an arrow, an arrow going from Ford Focus, going to car class, 140 00:09:44,200 --> 00:09:46,940 then going on top and going inside car class. 141 00:09:46,970 --> 00:09:54,370 OK, and also from all the three Audi A3 goes an arrow to car class and then goes straight inside car 142 00:09:54,370 --> 00:09:54,790 class. 143 00:09:55,110 --> 00:10:03,820 OK, so both both of these instances belong to car class and therefore they're called an instance of 144 00:10:03,820 --> 00:10:06,040 an object or an instance of a class. 145 00:10:06,910 --> 00:10:10,670 OK, there are several names for these instances. 146 00:10:10,690 --> 00:10:11,110 All right. 147 00:10:11,900 --> 00:10:16,270 This entity called an instance, you have several names for them, for it. 148 00:10:16,930 --> 00:10:22,480 And they're basically mean, the same instance of an object object instance or instance. 149 00:10:22,480 --> 00:10:27,340 You can find all of these names and stack overflow or in articles that you read on line. 150 00:10:27,640 --> 00:10:31,990 So each developer calls them differently, but it means the same thing. 151 00:10:34,180 --> 00:10:38,500 So this is basically what we have here, a declaration, which is the top part. 152 00:10:38,680 --> 00:10:41,550 And we have two instances of an object. 153 00:10:41,890 --> 00:10:47,800 OK, this is the first instance, Audi A3, this is this is the second instance, Ford Focus. 154 00:10:48,040 --> 00:10:50,860 And they're both belong to the car class. 155 00:10:51,080 --> 00:10:54,220 They're both instances of the car class. 156 00:10:55,060 --> 00:10:59,850 Um, I think this concludes the first part of classes. 157 00:11:00,550 --> 00:11:04,720 Let's discuss some more of these topics in the next lecture. 158 00:11:05,650 --> 00:11:11,740 I actually think that in the next lecture we will discuss what our properties of an object and what 159 00:11:11,740 --> 00:11:17,110 is a self parameter and also how to use object methods. 160 00:11:17,530 --> 00:11:17,980 All right. 161 00:11:19,430 --> 00:11:21,400 I think this is it for today. 162 00:11:21,400 --> 00:11:22,910 And I will see you in the next lecture. 163 00:11:22,930 --> 00:11:23,290 Thank you.