---
title: 'Learn Python DECORATORS in 7 minutes! 🎊'
source: 'https://youtube.com/watch?v=U-G-mSd4KAE'
video_id: 'U-G-mSd4KAE'
date: 2026-07-28
duration_sec: 441
---

# Learn Python DECORATORS in 7 minutes! 🎊

> Source: [Learn Python DECORATORS in 7 minutes! 🎊](https://youtube.com/watch?v=U-G-mSd4KAE)

## Summary

This video explains Python decorators, which are functions that extend the behavior of other functions without modifying them. The presenter uses an ice cream analogy to illustrate how decorators add functionality, like sprinkles or fudge, to a base function.

### Key Points

- **Definition of Decorators** [00:00] — A decorator is a function that extends the behavior of another function without modifying the base function.
- **Creating a Decorator** [00:44] — Define a decorator function that takes a function as an argument, defines an inner wrapper function, calls the passed function inside the wrapper, and returns the wrapper.
- **Applying a Decorator** [02:10] — Use the @decorator_name syntax above the base function definition to apply the decorator.
- **Why Wrapper Function is Necessary** [03:30] — Without the wrapper, the decorator would execute the base function immediately when applied, not when called.
- **Multiple Decorators** [04:20] — Multiple decorators can be stacked by placing them above the base function, and they execute in order from top to bottom.
- **Handling Arguments with *args and **kwargs** [05:31] — To pass arguments to the base function, the wrapper and the base function call should accept *args and **kwargs.

### Conclusion

Decorators are a powerful Python feature for extending functions without modification. They are applied with the @ syntax and can be stacked, and they handle arguments via *args and **kwargs.

## Transcript

What is going on everybody? So today I
got to talk about decorators in Python.
A decorator is a function that extends
the behavior of another function without
modifying that base function. We pass
the base function as an argument to the
decorator function. For example, let's
say we have a base function of get ice
cream and you can pass in a flavor of
ice cream. Well, some people might want
sprinkles on their ice cream and others
may not. They might just want plain
vanilla. Well, we could add sprinkles by
using a decorator. We're extending the
behavior of a function where we get ice
cream where we're adding sprinkles. But
we may not want to change the base
function because some people don't like
sprinkles. Think of decorators that way.
We're adding something to a base
function without changing it. Here's how
to create a decorator. Let's start with
the base function. We will create a
function to get ice cream. There will be
no parameters for now. All we're going
to do is print the following message.
Here is your ice cream. And for fun,
I'll add an emoji. I'll add an ice cream
emoji. To call this function, all I got
to do is call the get ice cream
function.
Here is your ice cream. Here's how to
create a decorator.
A decorator is a function. We'll need to
define it. define add sprinkles. Our
decorator function is going to have one
parameter, a function, but we'll just
rename it to funk for short. We're going
to pass a function to our decorator
function.
Within our decorator function, we will
define an inner function of wrapper.
Currently, there's no parameters. We'll
set that up later.
Within this wrapper function, we will
call the function that we receive this
parameter.
Then we will return our wrapper
function. Up until this point, we've
been returning values, but now we're
going to return an entire function.
Here's the basic formula to create a
decorator. To apply a decorator to a
base function, preceding that function,
you're going to add at the name of the
decorator. So add sprinkles is a
decorator. The base function is get ice
cream within our decorator. How do we
want to add sprinkles exactly? Currently
our decorator doesn't do anything.
Here's what happens. We just print here
is your ice cream. Let's say that before
we're given our ice cream, we'll print a
statement that we add sprinkles
within our decorator. Imagine that we're
replacing calling function with this
print statement.
Let's create another print statement
where we add sprinkles before it.
I will print the following message.
You add sprinkles. And I'll add an
emoji.
How about confetti? That could resemble
sprinkles.
Okay, let's see what happens.
You add sprinkles. Here is your ice
cream.
We're decorating our base function of
get ice cream with a decorator of add
sprinkles.
We're not modifying the base function.
We're extending it. Now, we have a
nested function of wrapper within our
decorator. It is necessary to have this.
Here's why. So, I'm not going to call
the get ice cream function quite yet.
So, nothing should happen.
If I was to remove this wrapper,
well, we'll end up calling this function
as soon as we apply the decorator. We're
not even calling the get ice cream
function at all. We only want to execute
this code when we want ice cream, not
whenever we apply the decorator.
That's why we need that wrapper
function.
We'll get ice cream and add sprinkles.
Only when we call that function,
then at any point in my program, if I
call the get ice cream function,
then we get ice cream with sprinkles.
Let's apply more than one decorator.
We'll create a decorator to add fudge.
Define add fudge.
We have one parameter, a function, which
we will rename as funk.
We need an inner wrapper function.
This is so that we don't call this
function when we apply a decorator.
I will print
you add fudge.
Close enough. We'll add a bar of
chocolate.
Then call the base function that we
receive.
Then we need to return the wrapper
function.
All right. Given our base function, we
can apply more than one decorator. Let's
say that after adding sprinkles,
we will apply the decorator where we add
fudge. So now
we have the following output.
You add sprinkles. You add fudge. Here
is your ice cream. So with decorators,
you can apply more than one decorator to
a base function.
What if your base function accepts
arguments? For example, when we get our
ice cream, we need to pass in a flavor
like vanilla.
I will set up one parameter of flavor. I
will convert our print statement to be
an fstring. Here is your add a
placeholder
flavor of ice cream. Let's run this and
see what happens.
All right, we have a type error. Our
wrapper function isn't set up to accept
arguments. What you'll see within
wrapper functions is that they'll have
parameters of args
and quarks to accept any number of
arguments and keyword arguments.
Then when you call your base function,
in this case get ice cream, we will also
set this up to accept any number of
arguments and keyword arguments. Let's
do that within our add fudge decorator
too. Our wrapper function will accept
any number of arguments and keyword
arguments. Same thing goes with the base
function. And now this should work.
You add sprinkles, you add fudge. Here
is your vanilla ice cream
or any other flavor of your choosing
like chocolate.
You add sprinkles. You add fudge. Here
is your chocolate ice cream. All right,
everybody. So those are decorators.
They're a function that extend the
behavior of a base function. In this
case, get ice cream. Decorators extend a
function without modifying it. If you
would like to apply a decorator to a
function, you preede that function when
you define it with at the name of the
decorator. And you can apply more than
one. And well everybody, that is an
introduction to decorators in Python.
