1 00:00:00,790 --> 00:00:05,530 Biton or be approach that is object oriented programming approach. 2 00:00:08,040 --> 00:00:16,170 Python is a mighty paradigm programming language as it supports different programming approach, and 3 00:00:16,170 --> 00:00:21,930 one of the popular approaches to solve a programming problem is by creating objects. 4 00:00:22,380 --> 00:00:29,660 And this is known as object oriented programming, that is, or B, so objects will be doing everything. 5 00:00:29,880 --> 00:00:34,270 So that's why you will be defining objects and using objects, be writing our code. 6 00:00:34,470 --> 00:00:40,770 And that is why, despite what is known as object oriented programming, language and object has two 7 00:00:40,770 --> 00:00:41,700 characteristics. 8 00:00:42,030 --> 00:00:44,550 The first one is the attributes or messages. 9 00:00:44,880 --> 00:00:50,430 That is, what are the different values these attributes can hold and behaviors or methods which will 10 00:00:50,430 --> 00:00:51,340 define that. 11 00:00:51,360 --> 00:00:57,450 What are the different palmitate operations that we can carry out on these attributes and messages? 12 00:00:59,320 --> 00:01:08,560 So let's take one example, so dog is an object, and it, as it has that name, age, height, weight, 13 00:01:08,560 --> 00:01:15,890 color, are the attributes and barking, wagging and this running are the respective behaviors. 14 00:01:16,300 --> 00:01:23,800 So the concept of object oriented programming in Python focuses on creating reusable codes that meets 15 00:01:23,800 --> 00:01:26,320 once the code will be defined, will be written. 16 00:01:26,470 --> 00:01:28,870 We can reuse that code as when required. 17 00:01:29,110 --> 00:01:34,270 So reusability will be enhanced if you go for the object oriented programming, because whatever the 18 00:01:34,270 --> 00:01:37,870 methods you are going to write, that can be used for any number of times. 19 00:01:38,170 --> 00:01:40,740 So this concept is also known as dry. 20 00:01:40,960 --> 00:01:43,300 That is, don't repeat yourself. 21 00:01:45,370 --> 00:01:50,070 In Python, the concept of object oriented programming follows some basic principles. 22 00:01:50,090 --> 00:01:55,030 So what are the principles where basically had three principles, that is the inheritance. 23 00:01:55,420 --> 00:01:57,130 Next one is the encapsulation. 24 00:01:57,130 --> 00:01:58,720 Next one is the polymorphism. 25 00:01:59,050 --> 00:02:04,800 So a process of using details from a new class without modifying the existing class. 26 00:02:05,230 --> 00:02:11,650 So the process of using details from a new class without modifying the existing class is known as the 27 00:02:11,650 --> 00:02:15,830 inheritance where the reusability code is getting implemented. 28 00:02:15,850 --> 00:02:21,730 That means there will be having one class from the class will be taking the respective methods and attributes, 29 00:02:22,150 --> 00:02:28,090 respective messages and methods in another class, and we can go on adding some other methods and messages 30 00:02:28,450 --> 00:02:29,680 as applicable. 31 00:02:29,980 --> 00:02:36,100 Next one is the encapsulation that is hiding the private details of a class from other objects. 32 00:02:36,250 --> 00:02:41,170 So class is nothing but a common blueprint for all the alike objects. 33 00:02:41,320 --> 00:02:48,910 So that is known as a class and in case of encapsulation, it will hide those private details of a class. 34 00:02:49,180 --> 00:02:51,010 And next one is a polymorphism. 35 00:02:51,190 --> 00:02:57,290 That is a concept of using common operation in different ways for different data input. 36 00:02:57,580 --> 00:02:59,350 So this is known as polymorphism. 37 00:02:59,560 --> 00:03:04,120 Whenever multiple things are the same thing will have a different name. 38 00:03:04,130 --> 00:03:09,190 Rather, I should say the same thing has got a different name, then we can call it as a polymorphic. 39 00:03:09,490 --> 00:03:16,060 So that's that's why its concept of using the common operation in different ways by saying different 40 00:03:16,060 --> 00:03:19,080 data input is known as a polymorphism. 41 00:03:19,240 --> 00:03:22,680 So these are the main three pillars of object oriented programming. 42 00:03:22,900 --> 00:03:29,620 So let us go for one demonstration, which will be showing you that how this python has become object 43 00:03:29,620 --> 00:03:30,160 oriented. 44 00:03:31,070 --> 00:03:35,630 In object oriented programming in Python, we define class and objects. 45 00:03:35,660 --> 00:03:38,810 We know that instance of a class is known as an object. 46 00:03:39,050 --> 00:03:44,750 An object consists of multiple different messages which will be holding different values and methods, 47 00:03:44,750 --> 00:03:50,820 which will decide who will determine the palmitate operations that we can carry out on those messages. 48 00:03:51,290 --> 00:03:52,670 Here we are defining one class. 49 00:03:52,670 --> 00:03:57,360 The name of the class is mainboard and this class is having three different methods. 50 00:03:57,560 --> 00:04:02,660 The first method is very special is underscored, underscore in it, underscore, underscore. 51 00:04:02,960 --> 00:04:06,080 This method is known as constructed. 52 00:04:06,320 --> 00:04:12,710 A constructor name will be will be Ollis underscored underscoring it underscore underscore irrespective 53 00:04:12,710 --> 00:04:13,490 of the class name. 54 00:04:13,640 --> 00:04:18,040 And it will have the prototype which will be having oneself as input argument. 55 00:04:18,320 --> 00:04:23,990 So this self is actually denoting the object reference that was object which will be created under this 56 00:04:23,990 --> 00:04:24,410 class. 57 00:04:24,650 --> 00:04:27,350 And this is also known as this reference. 58 00:04:27,770 --> 00:04:32,790 So this is this particular unit this constructed is having only one statement to get printed. 59 00:04:33,140 --> 00:04:38,000 Also, we are having other methods, that is of what type, and we are having the method that is cancer 60 00:04:38,000 --> 00:04:41,250 in whatever method is having this string to get printed. 61 00:04:41,270 --> 00:04:45,170 And this cancer is also having this string to get printed here. 62 00:04:46,250 --> 00:04:49,560 So in this way, we have declared the class body mainboard. 63 00:04:50,090 --> 00:04:51,980 So now we are going for this might Barat. 64 00:04:52,430 --> 00:04:57,290 And here we are having one instance, Biddable Spice's, which is having this string that is a bar here, 65 00:04:57,770 --> 00:05:01,400 and this is of a constructor which will print this respective message. 66 00:05:01,640 --> 00:05:04,720 And here we are defining two instance variables separately. 67 00:05:05,180 --> 00:05:09,290 One is name and age, which will get initialized with this input parameters. 68 00:05:09,800 --> 00:05:12,020 We are having another method that is that can sing. 69 00:05:12,290 --> 00:05:15,020 And this from this method are returning one string. 70 00:05:15,290 --> 00:05:18,020 And this is a string which will go on returning. 71 00:05:18,230 --> 00:05:25,500 And you see here we are passing this name as a placeholder content and this song as a placeholder content. 72 00:05:26,030 --> 00:05:28,810 So in this way, we have defined this my better class here. 73 00:05:29,540 --> 00:05:32,450 So now we are having the next class that is a penguin. 74 00:05:33,080 --> 00:05:36,650 This my penguin is inheriting the class mainboard. 75 00:05:37,010 --> 00:05:39,890 You can easily recall that this my bird was a class. 76 00:05:40,100 --> 00:05:45,320 And if you go on executing, you can find that it is having no method has been called from this mainboard 77 00:05:45,830 --> 00:05:46,250 class. 78 00:05:46,250 --> 00:05:50,180 So that is why it is producing no output, only the mere declaration we are having. 79 00:05:50,540 --> 00:05:54,710 And now we are having this my parrot and this might I have executed. 80 00:05:55,010 --> 00:05:56,590 So no, it has been observed. 81 00:05:56,930 --> 00:05:58,550 Now this is my penguin. 82 00:05:58,560 --> 00:06:02,510 This is one class which is inheriting properties from my part. 83 00:06:02,960 --> 00:06:05,920 So my bad properties means these properties will get inherited. 84 00:06:06,410 --> 00:06:12,380 We should know that when we are having one method or one message preceded by the underscore means, 85 00:06:12,380 --> 00:06:17,420 it is a private under the private and double undertaken means it is strictly private. 86 00:06:17,720 --> 00:06:21,380 Private members cannot be accessed from outside of the class. 87 00:06:22,220 --> 00:06:28,280 So this is my penguin, which is inheriting my bird class and it is having their respective constructor 88 00:06:28,280 --> 00:06:28,550 here. 89 00:06:28,880 --> 00:06:31,100 And who is calling the best class constructor? 90 00:06:31,100 --> 00:06:37,710 The best class means that my bad my bad constructor can only be called using dot underscored underscore 91 00:06:37,820 --> 00:06:39,560 in it underscore underscore method. 92 00:06:39,920 --> 00:06:42,170 That means we are calling the best class constructor. 93 00:06:42,530 --> 00:06:46,070 This super method is actually denoting the best class name. 94 00:06:46,370 --> 00:06:52,100 And what about the name of the best class it can be for using this super method and it is calling the 95 00:06:52,100 --> 00:06:54,410 best class constructor in the local function. 96 00:06:54,410 --> 00:06:56,930 But we are writing this that Pinguin is ready. 97 00:06:57,020 --> 00:06:57,470 Next one. 98 00:06:57,470 --> 00:06:58,310 You are having this. 99 00:06:58,340 --> 00:07:03,040 Who is this is a respective string to get printed can run. 100 00:07:03,050 --> 00:07:06,350 These are the method, the respective string will get printed here. 101 00:07:06,650 --> 00:07:13,250 So in this way we have defined my pinguin that this we have defined the my pinguin, which is inheriting 102 00:07:13,370 --> 00:07:14,530 mainboard class here. 103 00:07:15,050 --> 00:07:17,150 OK, so I'm writing this one as my pen. 104 00:07:17,300 --> 00:07:18,080 That will be better. 105 00:07:20,850 --> 00:07:25,650 So my penguin class inheriting the attributes from my bird class here. 106 00:07:26,130 --> 00:07:28,830 So now let us go for that instantiation. 107 00:07:28,860 --> 00:07:34,080 That means we shall declare some instance of the class in sense of the class means we're defining the 108 00:07:34,080 --> 00:07:35,910 object of the class here. 109 00:07:35,910 --> 00:07:37,320 The class name is my parrot. 110 00:07:37,480 --> 00:07:39,990 So we are calling the constructor so empty. 111 00:07:39,990 --> 00:07:41,150 One that is a parrot. 112 00:07:41,190 --> 00:07:42,480 One is equal to my parrot. 113 00:07:42,840 --> 00:07:47,970 My better one will be the name and then will be given as the value for this here. 114 00:07:48,300 --> 00:07:52,130 So you can find that it is will be passed and the name will be passed here. 115 00:07:52,410 --> 00:07:53,790 So that's why we're having this. 116 00:07:53,940 --> 00:07:58,310 My parrot one is a name and ages, then my parrot too is the name. 117 00:07:58,320 --> 00:07:59,920 Pipetting is the edge here. 118 00:08:00,090 --> 00:08:01,970 So in this way you have defined two objects. 119 00:08:02,100 --> 00:08:07,860 What is important and that one is mprda it is actually denoting my parrot one on my part or two. 120 00:08:08,670 --> 00:08:12,360 So now to access the class attributes we can write in this way. 121 00:08:12,540 --> 00:08:20,400 Impey one is eight so we can go for format and now be one dot class dot spaces so we can have this one. 122 00:08:20,410 --> 00:08:23,490 So this is nothing but one message. 123 00:08:23,490 --> 00:08:30,030 I think one member, whether we define that is suspicious and it is not under private because we haven't 124 00:08:30,540 --> 00:08:34,710 given any kind of underscore single or double before the is. 125 00:08:34,710 --> 00:08:38,210 So it is under the public school can be accessed from the outside. 126 00:08:38,580 --> 00:08:42,630 So that's why we're having this empty one dot class dot pieces. 127 00:08:42,810 --> 00:08:50,910 And now had we are having this is also a also the placeholder is there and format importunate class 128 00:08:51,150 --> 00:08:52,320 dot businesses. 129 00:08:52,620 --> 00:08:53,940 So now we are going for this. 130 00:08:54,120 --> 00:08:55,570 That is an instance aquiver. 131 00:08:55,590 --> 00:09:01,500 So now we are going for this empty one dot name, an empty one dot aides are going to get printed using 132 00:09:01,500 --> 00:09:07,980 this particular placeholders and dot format method so we that can string that windshear. 133 00:09:07,980 --> 00:09:09,950 We're having one method that is accounting. 134 00:09:10,230 --> 00:09:13,530 This can think you can find that this can be defined here. 135 00:09:14,100 --> 00:09:15,840 So it is our method is can sing. 136 00:09:16,080 --> 00:09:21,780 This particular method requires one string as input document the aspect of the song name. 137 00:09:22,050 --> 00:09:29,670 So here we are passing this, this IRP so that is the can sing is taking this particular string as input 138 00:09:29,670 --> 00:09:32,520 document and now we're having this. 139 00:09:32,520 --> 00:09:34,920 So let me go for the execution for the better clarity. 140 00:09:34,920 --> 00:09:35,700 You can find that. 141 00:09:39,030 --> 00:09:44,640 So my parrot class constructor is executing, so whenever we are calling this particular constructor 142 00:09:44,640 --> 00:09:51,050 to instantiate instance variables of this, my parrot, then my parrot class constructed is executing 143 00:09:51,090 --> 00:09:53,740 two times because we have defined two objects here. 144 00:09:53,970 --> 00:09:59,790 So just going to this, my party can easily find that he had written this my parrot class constructor 145 00:09:59,790 --> 00:10:00,440 is executing. 146 00:10:00,450 --> 00:10:06,780 So this line is producing the requesting as output and hear the name and age are getting initialized 147 00:10:06,780 --> 00:10:10,530 with this input parameters name and Agere so he can get it. 148 00:10:10,800 --> 00:10:13,170 OK, next we're going for this. 149 00:10:13,170 --> 00:10:21,210 That is the empty one is a you see MPLX one is a bird and MP two is also a is also a bird. 150 00:10:21,360 --> 00:10:26,400 Because here this business we initializes species with the string Baade here. 151 00:10:29,220 --> 00:10:35,460 OK, now we are printing this empty one name and one dot age, and it is giving the value as to my parrot. 152 00:10:35,490 --> 00:10:39,150 One is my favorite, one is 10 years of age. 153 00:10:39,270 --> 00:10:42,710 I mean, two is 15 years of age. 154 00:10:42,900 --> 00:10:46,350 So head MPU, MP one, that name is getting my parrot. 155 00:10:46,380 --> 00:10:49,240 One, we give that give that name and age. 156 00:10:49,240 --> 00:10:50,540 You have passed as ten. 157 00:10:50,610 --> 00:10:56,520 So they are getting printed and in this case to not name is getting instantiated with this my parrot 158 00:10:56,520 --> 00:11:00,660 to an MP 2.8 is getting instantiated with this whuppin. 159 00:11:00,810 --> 00:11:03,110 So accordingly we are getting the required outcome. 160 00:11:03,630 --> 00:11:05,660 So now we are having this can sing. 161 00:11:05,670 --> 00:11:09,540 So this is this particular method is producing this outputted. 162 00:11:10,080 --> 00:11:13,200 So here you can find that here we are going to have our output. 163 00:11:13,210 --> 00:11:14,370 That is my parrot. 164 00:11:14,380 --> 00:11:15,870 One can sing chirp. 165 00:11:16,140 --> 00:11:20,960 And here to see we have this particular string, C.H. IRP, there is a chart here. 166 00:11:21,300 --> 00:11:28,020 So this particular string is getting printed here because if you go to this can sing method, you can 167 00:11:28,020 --> 00:11:34,620 easily find that here we wrote this one, that is the respective name can sing this song here that this 168 00:11:34,620 --> 00:11:37,500 song has got initialized with the string scharper. 169 00:11:39,250 --> 00:11:45,130 OK, now we are going for another one, so we are going to define one object under the glass, my pinguin. 170 00:11:45,490 --> 00:11:49,060 So now this is our class might be and it has got the method that is. 171 00:11:49,140 --> 00:11:50,050 Who is this? 172 00:11:50,200 --> 00:11:51,310 And can run. 173 00:11:51,490 --> 00:11:55,050 These are respective strings are going to get printed using the printed function. 174 00:11:55,610 --> 00:12:04,150 So you wonder who is this busy one that can swing and bid you one dot can run here so you can find that 175 00:12:04,150 --> 00:12:10,420 this particular class, my pinguin, is having the instance functions, that that is our who is this 176 00:12:10,420 --> 00:12:13,060 and can run this mainboard. 177 00:12:13,300 --> 00:12:15,400 This my board that already defined. 178 00:12:15,400 --> 00:12:16,190 Here it is. 179 00:12:16,210 --> 00:12:18,620 I mean the method what type and can swim. 180 00:12:18,910 --> 00:12:23,680 So as a result of that this my pinguin is inheriting my part. 181 00:12:23,830 --> 00:12:31,510 So as it is that my body's defined the methods, the different methods can has got inherited into my 182 00:12:31,510 --> 00:12:33,630 pinguin so they can be accessed. 183 00:12:33,730 --> 00:12:40,390 So here to abuse this Bidgee one that can swim and pigeon dot can run here, you can easily find that 184 00:12:40,390 --> 00:12:45,010 inboard we're having this can swim and in Penguin we're having this can run. 185 00:12:45,190 --> 00:12:50,730 But from the might be an object I can access both can run and can swim. 186 00:12:50,890 --> 00:12:51,600 Exactly. 187 00:12:52,060 --> 00:12:53,490 So now you can find this one. 188 00:12:53,560 --> 00:12:56,490 So if, if we execute then Behnken is ready. 189 00:12:56,500 --> 00:12:59,620 This particular message is getting printed from the constructor. 190 00:12:59,920 --> 00:13:02,440 So here we are having the constructor here to operate in this. 191 00:13:02,440 --> 00:13:05,140 Pinguin is ready and now we're having this. 192 00:13:05,290 --> 00:13:08,320 I can swim, I can run faster. 193 00:13:08,500 --> 00:13:09,760 This I can swim. 194 00:13:09,760 --> 00:13:10,840 I can run faster. 195 00:13:10,840 --> 00:13:11,710 I can run faster. 196 00:13:11,710 --> 00:13:18,550 Has come from this can run, which is defined within this my being class, but as it is inheriting my 197 00:13:18,550 --> 00:13:19,210 weight class. 198 00:13:19,390 --> 00:13:23,020 So from my part I can swim now that is I can swim. 199 00:13:23,020 --> 00:13:26,770 This particular message is getting printed as we call this can swim method. 200 00:13:27,100 --> 00:13:31,600 So I think from this particular example, you are getting this idea how to define one class, how to 201 00:13:31,600 --> 00:13:34,080 define one object, what is inheritance? 202 00:13:34,090 --> 00:13:41,260 And when the inheritance is taking place, then how to access and the best class members from the class 203 00:13:41,260 --> 00:13:41,770 objects. 204 00:13:41,980 --> 00:13:43,300 So I think you are getting this idea. 205 00:13:43,300 --> 00:13:44,410 This is a record upward. 206 00:13:44,410 --> 00:13:45,930 We are going to get printed. 207 00:13:46,600 --> 00:13:48,370 So now let us go for it on the part. 208 00:13:49,550 --> 00:13:56,120 So here you are defining one class that is a personal computer to show you that what is that encapsulation 209 00:13:56,390 --> 00:14:02,300 in subject encapsulation, the member variables and the member functions will get encapsulated within 210 00:14:02,300 --> 00:14:03,000 the class. 211 00:14:03,410 --> 00:14:08,110 So in it, as I discussed earlier, that in it is nothing but one constructed here. 212 00:14:08,510 --> 00:14:13,620 This Max computer prize is nothing but one instance variable which has got initialized with the value. 213 00:14:13,640 --> 00:14:14,570 Twenty thousand. 214 00:14:15,110 --> 00:14:21,110 We're having another method that is a myself and having the method set max computer price so you can 215 00:14:21,110 --> 00:14:27,080 find that these are respective bodies are there and set max computer price is taken this price as input 216 00:14:27,080 --> 00:14:32,530 parameter and that price is instantiating or initializing max computer price. 217 00:14:32,540 --> 00:14:33,860 That is the instance variable. 218 00:14:34,550 --> 00:14:39,800 It is this personal computer class where you find one object, the name of the object is busy, busy 219 00:14:40,020 --> 00:14:40,630 myself. 220 00:14:41,150 --> 00:14:43,280 So this method is going to get executed. 221 00:14:43,760 --> 00:14:45,650 President Max Computer Prize. 222 00:14:45,920 --> 00:14:48,740 We've just upgraded that one using 30000 here. 223 00:14:48,980 --> 00:14:54,350 So beside myself, you see the respective method will get printed and set. 224 00:14:54,350 --> 00:14:55,540 Max computer prize. 225 00:14:55,550 --> 00:15:01,490 Again, we're calling this set Max computer price method, passing this price as input document input 226 00:15:01,490 --> 00:15:06,260 parameter, which will initialize this Max computer prize in standard variable. 227 00:15:06,440 --> 00:15:11,670 So again, if you go on printing myself, then obviously I shall be getting this updated prize here. 228 00:15:11,870 --> 00:15:13,610 So now let me go for the execution. 229 00:15:14,000 --> 00:15:16,820 You can find that selling price is twenty thousand. 230 00:15:16,820 --> 00:15:21,950 Initially, the selling price will be 20000 because max price within the constructor got initialized 231 00:15:21,950 --> 00:15:22,840 with 20000. 232 00:15:23,150 --> 00:15:25,900 So whenever we call this out myself. 233 00:15:26,150 --> 00:15:28,520 So Max Price has got printed as 20000. 234 00:15:28,520 --> 00:15:32,630 Opta that we did some update directly using the instance biddable. 235 00:15:33,020 --> 00:15:39,320 Then we did some update using this set Max computer price method and here the price has become 30000. 236 00:15:39,500 --> 00:15:45,590 So MYSEL has printed the selling price at 30000 after doing the opposite with the 40000 pieces that 237 00:15:45,590 --> 00:15:46,040 might sell. 238 00:15:46,040 --> 00:15:49,530 This method is printing selling price as 40000. 239 00:15:49,850 --> 00:15:58,340 So you are getting this idea how these glasses are having the respective messages and the methods encapsulated 240 00:15:58,340 --> 00:15:59,260 within the class. 241 00:15:59,720 --> 00:16:06,200 So I think now you are getting the idea in case of Python, how we can implement object oriented language 242 00:16:06,200 --> 00:16:06,710 features. 243 00:16:07,250 --> 00:16:08,480 Thanks for watching this video.