Introduction to Decorators

In the previous lesson, we learned about context managers and how we can write our own context managers using a Python concept called decorators. While we didn’t go much into the explanation of Python decorators, they’re such a critical concept to understand that we’ve decided to devote more time to explaining decorators.

In this third lesson of our Python Advanced Functions course, we’ll learn what Python decorators are, their role in functions, and why they’re important. While you may have seen decorators before, you may not have known they’re called that, and you probably don’t have much experience with using them yourself. This lesson will change that!

By the end of this lesson, you’ll have experience working with decorators, and you will be able to figure out when and how to use decorators to modify the behavior of a function. You will have also built intuition around how decorators make use of several Python concepts to work including closures, and the scope of a function.

As you learn about Python decorators and how to you them, you’ll apply everything you’re learning by writing code in our interactive Python environment. At each step, your code will be checked by our answer-checker so you can ensure that you’ve fully mastered each concept before moving on to the next lesson.


  • Learn how to use decorators.
  • Build intuition around how decorators work.
  • Understand nested functions, scope, and closures.

Lesson Outline

  1. Introduction
  2. Functions as Objects
  3. Nested Functions
  4. Scope
  5. Local vs Global Scope
  6. Scopes Continued
  7. Closures
  8. Closures Continued
  9. Introduction to Decorators
  10. Decorators
  11. Decorators Continued
  12. Next steps
  13. Takeaways

Get started for free

No credit card required.

Or With

By creating an account you agree to accept our terms of use and privacy policy.