Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Decorators 101 Recap and Review

Congratulations on getting this far. This video is a recap and review of this section. You’ve covered a couple of useful real world examples such as:

  • Boilerplate template for creating decorators that you can reuse
  • How to time functions
  • Using a decorator to build a debugging tool
  • Slow down code if you need to
  • Making a light-weight plugin architecture to register plugins
Download

Course Slides (PDF)

446.9 KB
Avatar image for Sammy-Boy

Sammy-Boy on Aug. 29, 2020

It’s super great tutorial. Just one question though what does this !r do in the f-strings? Maybe I missed it on a certain video.

Avatar image for Geir Arne Hjelle

Geir Arne Hjelle RP Team on Aug. 29, 2020

Hi Sammy-Boy.

The !r format specifier means that repr() should be used instead of the default str() when converting the variable.

For string variables it will in practice add single quotes around the string.

Avatar image for Ghani

Ghani on Oct. 23, 2020

Very informative course; thanks!

Avatar image for Pavel Anni

Pavel Anni on Jan. 10, 2021

Great tutorial, thanks! Time to think about how to apply it to my current projects :-)

Avatar image for rumeeahmad

rumeeahmad on Jan. 24, 2021

This is a very in depth and well explained view of decorators. This course has been fleshed out well and examples and use cases are relavent thus making it very simple for begginers to grasp their heads around.

My only reccomedation is to make sure some of the more obscure items are always explained a litle bit more in depth e.g. repr or !r.

Thanks

Avatar image for Mario Henrique Adaniya

Mario Henrique Adaniya on Feb. 20, 2021

I’m struggling a little bit in a code that make heavy usage of decorators. The course helped me to understand a little bit more about decorators… but still have tons of doubts.

Avatar image for 7ssanM

7ssanM on Oct. 16, 2021

Wonderful summary, easy to grasp, thank you very much Christopher and Real Python team.

Avatar image for aniketbarphe

aniketbarphe on Nov. 26, 2021

Thank You!

Avatar image for sndselecta

sndselecta on Jan. 7, 2024

Just to better understand. Decorators are basically something referred to as “wrapper functions”. It works as function itself, where a pre-definded function is input as an argument. The object of this wrapper function is to use the inputed function as is without altering its original code, with the additional advantage of imbedding new code before or after and ultimately returning the aggregated output.

Avatar image for Ash D

Ash D on Jan. 9, 2024

Incredible course - very well thought out and designed. The best RealPython course I’ve done so far (and I’ve done quite a lot!)

The best thing about this course is how much groundwork the teacher laid first, to avoid blowing our brains up when explaining decorators, a topic which most people find quite hard to grasp.

The design of this course shows a huge amount of thought about which aspects of decorators are the sticking point for most newbies, and how convey understanding about the precursor elements that make decorators easier to understand.

I was pleasantly surprised at how relevant and useful the examples were. I liked that the text-entry screen caps are sped up so that we’re not sitting there watching someone type slowly.

Fantastic work, RP team!

Become a Member to join the conversation.