top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

What is decorator in python and when it is used and useful ?

0 votes
57 views
What is decorator in python and when it is used and useful ?
posted May 27, 2017 by Vikram Singh

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

Hi,

Say you have function or class named XXX and you want to modify the functionality or property of XXX without modifying XXX then you can use decorator to do this.

E.g

def decorator_fun(old_function) :
*****def extended_old_function(arg1,arg2):
********return 2 * old_function(arg1,arg2);
******return extended_old_function;
def multiplier(arg1,arg2) :
*******return arg1*arg2;

double_multiplier = decorator_fun(multiplier);
print double_multiplier(10,20)

in the above example multiplier is a function which functionality is extended using decorator_fun.

answer May 29, 2017 by Jaganathan
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...