Skip to content
dreamcode
dreamcode
Map
Decorators
Lesson 52 of 77
+15 XP on finish
PYTHON ADVANCEDChapter 9 · Python Advanced

Custom decorators

A decorator wraps another function to modify its behavior without changing its code. They are denoted with @decorator_name.

Worked example

How it reads

  • def wrapper(text) defines the inner wrapping function that runs
  • @yell wraps the greet function inside yell
Cloud tip: Decorators are functions that take another function as an argument and return a new function.
main.py
PYTHON
real Python, runs in your browser
Console
Run your code to see its output here.
YOUR TURN

Make the wrapper also print Done after it calls func(), so the output is Starting, Working, Done.

Press Run to check your work.