What is a decorator?
Model answer
A function that takes a function and returns a new function with added behaviour, applied with @name above a definition. Common uses: logging, timing, caching (functools.lru_cache), and access checks. Use functools.wraps inside to keep the original name and docstring.
Learn this topic
The Python Standard Library: Dates, Counter, Statistics and More in the course Python for Beginners: Learn to Code with Real Projects.
Sign in to add your own answer.