What is a decorator in Python?

Experience Level: Junior
Tags: Python

Answer

A decorator in Python is a function that takes another function as its argument, and returns yet another function. Decorators can be extremely useful as they allow the extension of an existing function, without any modification to the original function source code.

Decorators are usually called before the definition of a function you want to decorate.

Python for beginners
Python for beginners

Are you learning Python ? Try our test we designed to help you progress faster.

Test yourself