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.

Mission 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

Course Info:


The median completion time for this course is 6 hours. View Details

This course requires a premium subscription. This course includes four missions.  It is the 27th course in the Data Scientist in Python path.


Take a Look Inside

(function(d) { d.addEventListener("DOMContentLoaded", function() { var pathname = d.location.pathname.replace(/^[/]|[/]$/g, "").replace("/", "-"); var tags = d.getElementsByTagName("iframe"); var type = pathname.startsWith("course") ? "?course=" : pathname.startsWith("path") ? "?path=" : null; if (type) { var i; for (i = 0; i < tags.length; i++) { if (tags[i].src.indexOf("signup#iframe") !== -1) { tags[i].src = tags[i].src.replace("#iframe", "") + type + pathname + "#iframe"; } } } }, false); })(document);