You are on page 1of 6

Decorators Introduction:

What are decorators?


Decorators are designed to enhance the functionality of other programs.

In this example we have one function printing Imran @ 420


Now we want to enhance the functionality of this function by adding one more printing statement that
prints Adnan Ashraf has designed his first decorator to reveal identity of Imran

We can add this functionality using wrapper function. Wrapper function wraps the original function and
execute it before other function and the call original function and completes.

Lets see how we have discovered and changed Imran @ 420 function using decorators.

Now suppose we want to add arguments in the in our original functions. Arguments of the original
functions are passed *arg and **kwarg are used as argument takers in the wrapper functions

Suppose we have discovered that Imran is not 420 and he is actually 720. Then we need to pass on this
to the argument as shown below.
Suppose our decorator has also an argument and it want to print that this a magical program to print
the identity of real legend in computer history 420---The Imran.
LAMBDA FUNCTIONS
MAP Function

You might also like