Python Decorators — Explain Like I'm 5

Magic Stickers for Your Functions

Imagine every function in your program is a toy robot with one job:

  • one robot says hello
  • one robot saves data
  • one robot sends an email

Now imagine you have special stickers:

  • a “log it” sticker that writes down every time a robot works
  • a “guard” sticker that checks if a person has permission
  • a “timer” sticker that measures how long the robot takes

A decorator is one of those stickers.

You place it above a function, and Python wraps that function with extra behavior. The function still does its main job, but now it also gets the sticker’s power.

def loud(func):
    def wrapper():
        print("Starting!")
        func()
        print("Done!")
    return wrapper

@loud
def wave():
    print("👋")

wave()

Output:

  • Starting!
  • 👋
  • Done!

The wave function did not change inside. We just gave it a wrapper.

Why this is useful

Without decorators, you would copy the same “check permission” or “print logs” code into many functions. That gets messy fast.

With decorators, you write that extra behavior once and reuse it everywhere.

One Thing to Remember

A decorator is a reusable wrapper: it adds behavior around a function before and after it runs, while keeping the original function code clean.

pythondecoratorsfunctionsbeginners

See Also

  • Python Async Await Async/await helps one Python program juggle many waiting jobs at once, like a chef who keeps multiple pots moving without standing still.
  • Python Basics Python is the programming language that reads like plain English — here's why millions of beginners (and experts) choose it first.
  • Python Booleans Make Booleans click with one clear analogy you can reuse whenever Python feels confusing.
  • Python Break Continue Make Break Continue click with one clear analogy you can reuse whenever Python feels confusing.
  • Python Closures See how Python functions can remember private information, even after the outer function has already finished.