0 votes
in Python Flask by
What are decorators in Python?

1 Answer

0 votes
by
In Python, functions are the first class objects, which means that:

Functions are objects; they can be referenced to, passed to a variable and returned from other functions as well.

Functions can be defined inside another function and can also be passed as argument to another function.

Decorators are very powerful and useful tool in Python since it allows programmers to modify the behavior of function or class. Decorators allow us to wrap another function in order to extend the behavior of wrapped function, without permanently modifying it.

@gfg_decorator

def hello_decorator():

print("Gfg")

'''Above code is equivalent to:

def hello_decorator():

print("Gfg")

hello_decorator = gfg_decorator(hello_decorator)'''

Related questions

0 votes
asked May 16, 2020 in Python by Robindeniel
0 votes
asked Jun 16, 2023 in Python Flask by john ganales
...