Biton decorator's, so let us define what is Biton decorator's.
Python has an additional and interesting feature called Decorator's to add functionality to one existing
code where having one existing code, but we can add some additional functionality with the existing
one.
This is also called metaprogramming as a part of the program tries to modify another part of the program
at the compiler.
So let us go for one practical demonstration to implement and to see what is decorator's in Python.
Python is having a very interesting feature, which is known as the decorator's and which will add functionality
to an existing code.
And this is also known as metaprogramming as a part of the program tries to modify.
By another part of the program at the Campbeltown to discuss more about this decorator's, let us consider
this example.
Here we are having one simple function, that simple function name is also simple function.
So print, I am a simple function.
OK, so now if I execute, this could obviously this line will get printed.
But here we are defining one decorator.
So that is a function is that the name of the function is make decorated, which will take a function
as input.
And this is the inner function here.
So the inner function.
So print I got decorated and this function which will be passed as simple document, that function will
get printed and this inner function will be returned here.
So now you see I'm calling this function that is a decorated samake, decorated and passing the simple
function as an input parameter.
So this simple function will be assigned to this function, this line will get printed and this particular
function will execute its body.
So I am a simple function will get executed and then the inner function, the reference will be returned
and that has been assigned to this decor.
So now when the point from this, the code we are calling this function, we are getting the output
like this one.
So I got decorated.
So this particular line has got printed in the function which has been passed as input document.
That is a simple function.
The body will get printed.
So I am a simple function.
So I am a simple function is getting executing.
So this particular thing can also be done in this way.
I'm just showing you.
So here to see you are defining that with the symbol at the rate of where defining this decorative function
name.
So we're writing this one, a very simple one, so at the rate of make decorated, so whenever this
simple function will be called, then make decorated will be called by default automatically so I can
show you.
So I'm going for this simple function.
So now you see, I'm just it is about.
So I'm going for this execution and finding that I got decorated, I am a simple function is having
the respective outputs fingerprinted.
So here, whenever this simple function to be called it would be called the make decorated function
would be called and this make decorated will automatically take this simple function as input parameter
and the respective people will get executed, as I explained.
So writing these two lines and without writing this one will have the same effect if we write this particular
line that is a decorative function name preceded by this other top symbol and don't write this one.
Just calling this function directly, it will produce the same output as I have demonstrated.
So it go for another example for the easy understanding.
So another example is with us.
So let's go for that.
So here you are having this my smart division.
So there is one function undefined, which will take this function as input document.
So I think there is a decorator function we are having.
The main function is Avago Divide, which will just perform a baby and the value returned.
But here you see that the function name has been written after this at the rate of Simbel, as I did
before.
So this is of an inner function, X and Y.
This X and Y value will be this particular parameter will get evolutis A and B and I am dividing X and
Y.
If Y is a digital division by zero is illegal, dismisses will get printed and return address this return
function XCOM away.
So this particular function value will be returned here and then we're having this function, our function
here.
So now here to see where this barometer there is a 20 and two, so to intenta will be assigned to this
and B so there is a 22 and that very decorative function will be called this go divide will be the input
document to this decorative function.
So func this twenty and these two will be assigned to this X and Y at the respective outputs will be
hoplin.
I'm just going to show you I'm dividing and this message is coming from this line here is he the are
two is not equal to zero.
So this particular line, this particular block is not getting executed.
So return function x y, so excited that division will take place and the value will be returned and
the value will be ten point zero.
And but in this case, when I'm passing this A B as zero here, so oops, division by zero is illegal
and this message is getting printed and it returns nothing.
So that's right.
And returns nothing that that's why the Non is getting printed.
So generally we decorate the function and assign it as good.
Divide is equal to my smart div go divide.
So actually when I, when I'm just mentioning this decorative function here after this at the REDUB
symbol and whenever this decorative function is, whenever the function is getting defined, actually
we're actually writing this one as good divide is equal to my smart div codified.
So in this way, in this particular demonstration I've shown you that how to use this decorator functions
and decorators in our python coding.
Thanks for watching this video.