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.
Related Python job interview questions
What does [2:] syntax do on str in Python?
Python JuniorHow do you create a set with 3 values in Python?
Python JuniorWhy would you return self from a class method?
Python JuniorHow do you detect if the optional parameter value was set?
Python JuniorHow do you define an optional parameter with no value in Python?
Python Junior