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

Different types of data in python3
Python3 features Numbers(int,float,complex), String, Lists, Tuples, Dictionary and Sets type of data. long interger type numbers from python2 is no longer required. Below are examples of all python3 data...

Python - Solving Ordinary Differential Equations - Predator Prey Model aka Lotka Volterra Equations
This is an assignment in Python, I contributed to a numerical Python MOOC from George Washington University. The link to this assignment on github is here. The Lotka–Volterra equations, also...
S

Sri Vallabha Deevi

0 0
1

Identity operators
Identity operators Operation Syntax Function Identity a is b is_(a, b) Membership operators Operation Syntax Function Containment obj in seq contains(seq, obj)

A python program using the datetime module
Task : To write a program in Python to find out, in any given year, Friday the 13th dates i.e 13th day of a month which was a Friday. ...

Learn Python : Formatting with the .format () method
A good way to format objects into your strings for print statements is with the string.format() method. The syntax is :'String here {} then also {}'.format('something1','something2')Example 1:print("This...
B

Biswanath Banerjee

0 1
0
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