1 00:00:07,520 --> 00:00:15,320 Now, writing your code can introduce sometimes to a lot of retyping the same line of code over and 2 00:00:15,320 --> 00:00:20,780 over again, and a very simple way to avoid that is by inheritance. 3 00:00:21,230 --> 00:00:24,100 And I will show you what the problem is and how to solve it. 4 00:00:24,470 --> 00:00:32,780 So let's see that we have a class that is creating German people so German and then will create a method 5 00:00:32,780 --> 00:00:34,790 here speak. 6 00:00:35,890 --> 00:00:39,570 And who print speaking, right? 7 00:00:41,840 --> 00:00:51,290 Then our friend Marc Klaas, and this will be called French, and I will right here, T.F. speak French 8 00:00:52,100 --> 00:00:52,980 speaking. 9 00:00:54,140 --> 00:00:56,510 So do see where the problem is here? 10 00:00:56,960 --> 00:01:01,750 Well, here you basically have the same method in the two functions. 11 00:01:02,090 --> 00:01:09,230 So isn't it better to have the method defined only in the one function and then simply send in some 12 00:01:09,230 --> 00:01:10,830 way with the rest of the functions? 13 00:01:11,120 --> 00:01:18,550 For example, we him here for 50 more countries, then this pretty much becomes a problem because you 14 00:01:18,560 --> 00:01:20,460 need to create the same method 50 times. 15 00:01:20,930 --> 00:01:27,570 So, yes, there is actually an easy way to solve this, and this is by inheritance. 16 00:01:27,890 --> 00:01:35,270 So if I create another class in the class will be called human and I will simply copy and paste this 17 00:01:35,580 --> 00:01:36,050 in the class. 18 00:01:37,040 --> 00:01:38,260 So we have it there as well. 19 00:01:38,830 --> 00:01:46,760 So now since the German and the French and they're both humans and they both can speak, what you can 20 00:01:46,760 --> 00:01:52,310 do is to dismantle from here and aragón the brackets human. 21 00:01:53,090 --> 00:02:01,640 And this means that the German will basically get all the medals from the class human or it will inherit 22 00:02:01,640 --> 00:02:01,870 them. 23 00:02:02,390 --> 00:02:08,220 And this you can do when you inherit the method of the class that is higher level than yours. 24 00:02:08,480 --> 00:02:11,570 So for example, your first human and then you German. 25 00:02:11,960 --> 00:02:18,650 So basically the German will inherit all the features of the class from which you can see error here. 26 00:02:18,650 --> 00:02:23,240 And this is because Python don't like when you don't have anything inside your class. 27 00:02:23,450 --> 00:02:31,170 And for that reason you can write here pass, which basically says that you should pass this line without 28 00:02:31,170 --> 00:02:31,850 the initials. 29 00:02:31,850 --> 00:02:35,050 And you can see that now our error is removed. 30 00:02:35,360 --> 00:02:39,820 And this is the same for the French pass and also right here. 31 00:02:40,280 --> 00:02:40,740 Sure. 32 00:02:41,720 --> 00:02:44,900 So now let's create a French class, for example. 33 00:02:46,430 --> 00:02:48,710 Let's Steffon be a French person. 34 00:02:48,950 --> 00:02:50,210 So are as different. 35 00:02:50,210 --> 00:02:51,980 Of course, French. 36 00:02:52,490 --> 00:02:52,930 Right. 37 00:02:53,210 --> 00:02:54,650 And now if I write. 38 00:02:55,640 --> 00:03:02,270 So we feel right, Stefan, and the right not after, but you can see that we are getting the speaker's 39 00:03:02,270 --> 00:03:06,860 proposal, which means that we successfully inherited the Speakman. 40 00:03:07,750 --> 00:03:09,370 And now let's run the code now. 41 00:03:09,830 --> 00:03:15,710 And you can see that now Steffon can speak because it's heard that the method from the human plus.