Python - Decorators


Decorators decorate functions. They themselves are functions that accept a function and return a function.

Decorators get applied using a special syntax.

@suppress_errors
def show_errors():
    pass

In the above the decorator is the @suppress_errors statement.

Decorators are important in that they allow a set of common tasks to be performed by many different functions, ususlaly before or after doing something more specific to the target function.

Common areas where decorators get applied include: access control, error handling, caching, logging, mapping routes to functions etc.

Without decorators you would need to copy code several times to perform that task before or after the target function is executed.

How do You Feel after reading this?

According to scientists, we humans have 8 primary innate emotions: joy, acceptance, fear, surprise, sadness, disgust, anger, and anticipation. Feel free to tell us how you feel about this article using these emotes or via the comment section. This feedback helps us gauge our progress.

Help me Grow.

I set myself some growth ambitions I desire to achieve by this year's end regarding this website and my youtube channel. Am halfway. Help me reach them by:




Recommendations


What do You Think

Dear readers drop us your comments below. We are building a community of students and learners. Start by dropping us your suggestions below. What tutorials do you want us to do for example? Where can we improve? What are some awesome resources out there? Do you have any code you want to share with us?
By the way that example or snippet you have lying in your computer can really help beginner programmers. We can share it here with other students.

Previous Post Next Post