0 votes
in Python by

What are decorators in Python?

1 Answer

0 votes
by

Decorators belong most probably to the most beautiful and most powerful design possibilities in Python, but at the same time the concept is considered by many as complicated to get into. To be precise, the usage of decorators is very easy, but writing decorators can be complicated, especially if you are not experienced with decorators and some functional programming concepts.

Even though it is the same underlying concept, we have two different kinds of decorators in Python:

  • Function decorators
  • Class decorators

A decorator in Python is any callable Python object that is used to modify a function or a class. A reference to a function "func" or a class "C" is passed to a decorator and the decorator returns a modified function or class. The modified functions or classes usually contain calls to the original function "func" or class "C".

 

Related questions

0 votes
asked Dec 19, 2019 in Python by sharadyadav1986
0 votes
asked Oct 12, 2021 in Python by rajeshsharma
...