Sitemap
Bhavatharani

Bhavatharani

DECORATORS IN PYTHON

May 19, 2022

--

Press enter or click to view image in full size

Python has an interesting feature called decorators to add functionality to an existing code.

This is also called metaprogramming because a part of the program tries to modify another part of the program at compile time.

Get Bhavatharani’s stories in your inbox

Join Medium for free to get updates from this writer.

There are three rules of functions:

  1. Reference of a function to another function
  2. A function name can be passed as an argument
  3. A function can return another function

Syntax for Decorator:

@gfg_decorator
def hello_decorator():
print("Gfg")
'''Above code is equivalent to -def hello_decorator():
print("Gfg")

hello_decorator = gfg_decorator(hello_decorator)'''

--

--