Decorator in python
- A decorator in Python is a function that takes another function as an argument, while not changing the function being used as an argument.
- Decorators dynamically alter the functionality of a function without using sub classes.
- This is useful when you want to extend the functionality of functions and don’t want to modify them.
Example:
def decorator(func):
def wrapper():
print "Hello Wikitechy"
print func("Hai")
print "How r you?"
return wrapper
def some_random_function(hello):
return hello
decorated_function = decorator(some_random_function)
decorated_function()
Categorized in:
Tagged in:
Accenture interview questions and answers, Applied Materials interview questions and answers, Atos interview questions and answers, Capgemini interview questions and answers, CASTING NETWORKS INDIA PVT LIMITED interview questions and answers, CGI Group Inc interview questions and answers, Chetu interview questions and answers, Collabera Technologies interview questions and answers, decorator pattern python, Dell International Services India Pvt Ltd interview questions and answers, Flipkart interview questions and answers, Genpact interview questions and answers, IBM interview questions and answers, Indecomm Global Services interview questions and answers, Infosys Technologies interview questions and answers, L&T Infotech interview questions and answers, Mavenir interview questions and answers, Mphasis interview questions and answers, NetApp interview questions and answers, Oracle Corporation interview questions and answers, PeopleStrong interview questions and answers, Persistent Systems interview questions and answers, Prokarma Softech Pvt Ltd interview questions and answers, python built in decorators, python class decorator, python class method decorator, python class property decorator, python data science interview questions, python decorate class method, python decorator class, python decorator class vs function, python decorator example, python decorator library, python decorator with arguments, python decorators explained, python decorators with arguments, python interview questions and answers for testers, python multiple decorators, python programming questions, python property decorator, python telephonic interview questions, Reliance Industries Ltd interview questions and answers, SAP Labs India Pvt Ltd interview questions and answers, Tech Mahindra interview questions and answers, UnitedHealth Group interview questions and answers, Virtusa Consulting Services Pvt Ltd interview questions and answers, Wells Fargo interview questions and answers, what is a decorator in python, what is decorator in python, Xoriant Soluti interview questions and answers