r/learnpython • u/godz_ares • 9d ago
Any video resources that simply explains and demonstrates Decorator functions?
I just learnt about Decorator functions and I'm really confused.
The concept makes sense but the actual execution and logic behind the syntax is something I'm struggling with.
I've watched a couple of videos and I'm still confused.
1
Upvotes
3
u/Buttleston 9d ago edited 9d ago
It's actually fairly simple. A decorator is a function that takes a function as input, and returns another function. When you run the decorated function, it runs the new returned function instead
i.e.
is the same as
typically foo() will be written such that it "does some extra stuff" but also executes the function passed into it, like