1 00:00:00,580 --> 00:00:05,650 Biton decorator's, so let us define what is Biton decorator's. 2 00:00:07,390 --> 00:00:15,610 Python has an additional and interesting feature called Decorator's to add functionality to one existing 3 00:00:15,610 --> 00:00:21,130 code where having one existing code, but we can add some additional functionality with the existing 4 00:00:21,130 --> 00:00:21,340 one. 5 00:00:21,850 --> 00:00:28,750 This is also called metaprogramming as a part of the program tries to modify another part of the program 6 00:00:28,750 --> 00:00:29,590 at the compiler. 7 00:00:30,070 --> 00:00:36,940 So let us go for one practical demonstration to implement and to see what is decorator's in Python. 8 00:00:37,870 --> 00:00:44,440 Python is having a very interesting feature, which is known as the decorator's and which will add functionality 9 00:00:44,440 --> 00:00:45,870 to an existing code. 10 00:00:46,270 --> 00:00:50,800 And this is also known as metaprogramming as a part of the program tries to modify. 11 00:00:53,660 --> 00:01:00,470 By another part of the program at the Campbeltown to discuss more about this decorator's, let us consider 12 00:01:00,470 --> 00:01:01,360 this example. 13 00:01:01,700 --> 00:01:05,980 Here we are having one simple function, that simple function name is also simple function. 14 00:01:06,320 --> 00:01:08,150 So print, I am a simple function. 15 00:01:08,440 --> 00:01:12,440 OK, so now if I execute, this could obviously this line will get printed. 16 00:01:12,680 --> 00:01:15,030 But here we are defining one decorator. 17 00:01:15,350 --> 00:01:20,870 So that is a function is that the name of the function is make decorated, which will take a function 18 00:01:20,870 --> 00:01:21,470 as input. 19 00:01:21,860 --> 00:01:23,700 And this is the inner function here. 20 00:01:23,720 --> 00:01:25,300 So the inner function. 21 00:01:25,730 --> 00:01:31,190 So print I got decorated and this function which will be passed as simple document, that function will 22 00:01:31,190 --> 00:01:34,890 get printed and this inner function will be returned here. 23 00:01:35,420 --> 00:01:41,450 So now you see I'm calling this function that is a decorated samake, decorated and passing the simple 24 00:01:41,450 --> 00:01:43,560 function as an input parameter. 25 00:01:43,760 --> 00:01:49,190 So this simple function will be assigned to this function, this line will get printed and this particular 26 00:01:49,190 --> 00:01:50,890 function will execute its body. 27 00:01:51,110 --> 00:01:57,670 So I am a simple function will get executed and then the inner function, the reference will be returned 28 00:01:57,740 --> 00:01:59,940 and that has been assigned to this decor. 29 00:02:00,050 --> 00:02:04,670 So now when the point from this, the code we are calling this function, we are getting the output 30 00:02:04,670 --> 00:02:05,290 like this one. 31 00:02:05,720 --> 00:02:07,210 So I got decorated. 32 00:02:07,790 --> 00:02:12,440 So this particular line has got printed in the function which has been passed as input document. 33 00:02:12,440 --> 00:02:13,690 That is a simple function. 34 00:02:14,120 --> 00:02:15,320 The body will get printed. 35 00:02:15,350 --> 00:02:16,940 So I am a simple function. 36 00:02:16,950 --> 00:02:19,310 So I am a simple function is getting executing. 37 00:02:20,060 --> 00:02:22,540 So this particular thing can also be done in this way. 38 00:02:22,550 --> 00:02:23,230 I'm just showing you. 39 00:02:23,810 --> 00:02:30,440 So here to see you are defining that with the symbol at the rate of where defining this decorative function 40 00:02:30,450 --> 00:02:30,600 name. 41 00:02:32,770 --> 00:02:38,770 So we're writing this one, a very simple one, so at the rate of make decorated, so whenever this 42 00:02:38,770 --> 00:02:44,350 simple function will be called, then make decorated will be called by default automatically so I can 43 00:02:44,350 --> 00:02:44,830 show you. 44 00:02:45,370 --> 00:02:47,320 So I'm going for this simple function. 45 00:02:50,880 --> 00:02:53,280 So now you see, I'm just it is about. 46 00:02:54,440 --> 00:03:00,590 So I'm going for this execution and finding that I got decorated, I am a simple function is having 47 00:03:00,590 --> 00:03:02,420 the respective outputs fingerprinted. 48 00:03:02,930 --> 00:03:08,150 So here, whenever this simple function to be called it would be called the make decorated function 49 00:03:08,150 --> 00:03:13,910 would be called and this make decorated will automatically take this simple function as input parameter 50 00:03:14,150 --> 00:03:17,140 and the respective people will get executed, as I explained. 51 00:03:17,540 --> 00:03:23,900 So writing these two lines and without writing this one will have the same effect if we write this particular 52 00:03:23,900 --> 00:03:30,350 line that is a decorative function name preceded by this other top symbol and don't write this one. 53 00:03:30,350 --> 00:03:35,150 Just calling this function directly, it will produce the same output as I have demonstrated. 54 00:03:35,480 --> 00:03:38,310 So it go for another example for the easy understanding. 55 00:03:38,840 --> 00:03:40,690 So another example is with us. 56 00:03:40,700 --> 00:03:41,840 So let's go for that. 57 00:03:42,560 --> 00:03:45,130 So here you are having this my smart division. 58 00:03:45,170 --> 00:03:49,620 So there is one function undefined, which will take this function as input document. 59 00:03:49,650 --> 00:03:52,220 So I think there is a decorator function we are having. 60 00:03:52,730 --> 00:03:57,860 The main function is Avago Divide, which will just perform a baby and the value returned. 61 00:03:58,200 --> 00:04:03,800 But here you see that the function name has been written after this at the rate of Simbel, as I did 62 00:04:03,800 --> 00:04:04,200 before. 63 00:04:04,610 --> 00:04:06,740 So this is of an inner function, X and Y. 64 00:04:06,740 --> 00:04:13,700 This X and Y value will be this particular parameter will get evolutis A and B and I am dividing X and 65 00:04:13,700 --> 00:04:14,150 Y. 66 00:04:14,300 --> 00:04:22,220 If Y is a digital division by zero is illegal, dismisses will get printed and return address this return 67 00:04:22,220 --> 00:04:23,650 function XCOM away. 68 00:04:23,900 --> 00:04:29,330 So this particular function value will be returned here and then we're having this function, our function 69 00:04:29,330 --> 00:04:29,570 here. 70 00:04:30,020 --> 00:04:36,530 So now here to see where this barometer there is a 20 and two, so to intenta will be assigned to this 71 00:04:36,720 --> 00:04:44,060 and B so there is a 22 and that very decorative function will be called this go divide will be the input 72 00:04:44,060 --> 00:04:46,160 document to this decorative function. 73 00:04:46,430 --> 00:04:52,130 So func this twenty and these two will be assigned to this X and Y at the respective outputs will be 74 00:04:52,130 --> 00:04:52,470 hoplin. 75 00:04:52,490 --> 00:04:59,250 I'm just going to show you I'm dividing and this message is coming from this line here is he the are 76 00:04:59,330 --> 00:05:01,120 two is not equal to zero. 77 00:05:01,130 --> 00:05:04,550 So this particular line, this particular block is not getting executed. 78 00:05:04,790 --> 00:05:10,220 So return function x y, so excited that division will take place and the value will be returned and 79 00:05:10,220 --> 00:05:11,810 the value will be ten point zero. 80 00:05:12,200 --> 00:05:19,100 And but in this case, when I'm passing this A B as zero here, so oops, division by zero is illegal 81 00:05:19,310 --> 00:05:22,610 and this message is getting printed and it returns nothing. 82 00:05:22,880 --> 00:05:23,870 So that's right. 83 00:05:24,530 --> 00:05:27,670 And returns nothing that that's why the Non is getting printed. 84 00:05:28,160 --> 00:05:32,770 So generally we decorate the function and assign it as good. 85 00:05:32,780 --> 00:05:36,600 Divide is equal to my smart div go divide. 86 00:05:36,620 --> 00:05:43,440 So actually when I, when I'm just mentioning this decorative function here after this at the REDUB 87 00:05:43,460 --> 00:05:48,890 symbol and whenever this decorative function is, whenever the function is getting defined, actually 88 00:05:49,460 --> 00:05:54,490 we're actually writing this one as good divide is equal to my smart div codified. 89 00:05:54,860 --> 00:06:01,670 So in this way, in this particular demonstration I've shown you that how to use this decorator functions 90 00:06:01,670 --> 00:06:04,340 and decorators in our python coding. 91 00:06:04,880 --> 00:06:06,110 Thanks for watching this video.