Hi and Hello everyone. This is facilitator commander for this course decorators in Python. This is our last, in fact, second last lecture on Python decorators. Here we are going to summarize our learning, we need to discuss one more example lubricated by them decorators. And at the end, we'll be discussing the exercise that that I'm giving you to solve in order to give me the feedback about whether you would be able to solve the exercise or not. And the last video would obviously be the solution to the exercise.
So overall, we started discussing the decorators its importance and how and where it could be used. Its index, its workflow and logic, and then we discussed few examples. And it ranged from simple to a bit more complex. And this video will just summarize all the things so what is actually What a Python decorator does it dynamically alter the functionality of a function method or class without actually changing the source code or key without creating the subclasses. So with this, we also serve the main functionality are the feature of the Python that is don't repeat yourself. And but this removed two, use cases of the button decorators.
Number one, it is authorization and framer, it is us not traditional Python frameworks such as flask and Django. Number two is it is used for logging logging calls and logging output maybe reserves we also discussed this in the in the in the former importance where transaction reports were required to be created for audit purpose. Then measuring the execution time Yes, that could be used. So if we need to check out is the execution time of function. We could check it Using the decorator by creating the decorator and decorating the function that we need to check for execution time, and synchronization as well. You can see a number of decorator examples on this website that is wiki Python dot o RG but the decorator library.
So let's see this. So there are a number of examples. And separate portable for Python decorators. You can go through this and if you have any queries you can contact me back. And for that also, you can get connected with me on my YouTube channel, subscribe to my YouTube channel. You can connect with me on twitter on YouTube me on on, on medium where I write blog as well so you can get connected to me and in case of any question you can ask me anytime, and I'd definitely love to answer your queries.
The next thing is we're just going to create a Simple Python decorator function, but it is in terms of code, it is simple, but it does a very important function it enables and disables the function. So, if I write down definition and change and pass function to it as a parameter and then returns the same function, it is going to do it is not going to do any change in the behavior. So, it is kind of like keeping the function as it is that is being decorated but if you want disable the function, we can create another function within a decorator function and pass in the argument and key value argument as required or as is required in the given the function to be decorated and then an empty function that doesn't do any thing like it just passes. So, let's execute this might executed. Let's move on.
Now. We've created a sample show greeting function when we execute this Just going to print and and when we disable the same show function and just execute this and move towards execution of this function, it doesn't do anything because we've already disabled the function. Now, there would be other use cases as well like repeating function twice, we can use decorators for this. We can also use decorators for like checking if the argument passed is an integer string etc. We can do mathematical operations on output of a function using decorators. So there are numerous use cases that you can do with the decorators and the best thing about it is you can use decorators with multiple functions at the same time.
So the purpose like don't repeat yourself is very well served with this the SEC raters now let's discuss the exercise, you'll have to create a decorated function with one argument. And check it the argument being passed within the function is an integer or a string. And if that is not a string or an integer, you should print the decorator function should pankot print wrong type. And you can easily do this I'll share you with the simple format. This is the check type decorator function that you need to create. And when you're going to add and when that decorator is created, you can pass the function to be decorated with this decorator and check if that checks whether the interior is passed or not.
And even if this is not a teacher you should it should print around tight And CMV if a string is fast and when sync is required, and the same string is passed, it should execute but when a string is required and the string is not passed as a parameter, and the function is being decorated with the check type, it should print that wrong datatype being passed with the function I hope this is scare me have any goodies you can definitely contact me. And for that you can subscribe to YouTube, Twitter or you to me or our medium channels and may you make any queries you can feel free to contact me. Thank you