What are decorators in python

Python course



Decorators are probably one of the most powerful design options in Python. At the same time, most people find it difficult to get started. To be more precise, using decorators is easy. But writing decorators can be tricky, especially if you're not very experienced. There are two different types of decorators in Python:
  • Functional 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 the decorator and the decorator returns a modified function or class. The modified functions or classes usually call the original function "func" or class "C" internally.

You can also work through the chapter on memoization.

Since the maintenance and expansion of four different Python tutorials - ie Pyt hon2 in German and English and also Python3 in both languages ​​- means an enormous amount of work, we have decided to focus mainly on the German and English tutorials for Python3 in the future to concentrate.

We therefore recommend that you continue reading this chapter "Introduction to Decorators" in the Python3 tutorial.