UrbanPro
true

Learn Python Training from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

Decorators In Python

Praveen Choudhary
19/02/2018 0 0

A decorator takes in a function, adds some functionality and returns it.

Functions and methods are called callable as they can be called.

Any object which implements the special method __call__() is termed callable.

A decorator is a callable that returns a callable.

A decorator takes in a function, adds some functionality and returns it.

def make_pretty(func):
           def inner():
                 print("I got decorated")
                 func()
           return inner

def ordinary():
           print("I am ordinary")

ordinary() #outputs "I am ordinary"
# let's decorate this ordinary function
pretty = make_pretty(ordinary)
pretty()

#outputs:
I got decorated
I am ordinary
#make_pretty() is a decorator.
#pretty = make_pretty(ordinary)
#The function ordinary() got decorated and the returned function was given the name pretty.

0 Dislike
Follow 2

Please Enter a comment

Submit

Other Lessons for You

Python Introduction
Python is an object-oriented programming language created by Rossum in 1989. It is ideally designed for rapid prototyping of complex applications. It has interfaces to many OS system calls and libraries...
I

Imran

0 0
0

The Zen of Python
Writing programs that actually do what they are supposed to do is just one component of being a good python programmer. It's also important to write clean code that is easily understood, even weeks after...


Writing Simple programs in Python(cont.)
To start writing simple programs in Python, we have to know firstly the SW development process and then we also have to know a bit about the language in which we wish to code,in this case,python, to get...

A program to calculate Correlation Coefficient
Task: Calculating the Correlation-coefficient using Python We know that the correlation coefficient is calculated using the formula nΣxy- ΣxΣy / (√(nΣx^2-(Σx)^2)...
X

Looking for Python Training Classes?

The best tutors for Python Training Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn Python Training with the Best Tutors

The best Tutors for Python Training Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more