Member-only story

Why You Need Decorators in Your Python Code

Metaprogramming is key

Michael Krasnov
Better Programming
Published in
3 min readAug 6, 2020

Photo by Free Photos on Pixabay.

Python is praised for its clarity and syntactic sugariness. In this article, I will teach you to use decorators in Python to make your code readable and clean.

What Are Decorators?

To understand what decorators are, you first need to be familiar with the way Python handles functions. From its point of view, functions are no different than regular objects. They have properties and can be reassigned:

Moreover, you can pass them as arguments to other functions:

Now, to decorators. A decorator is used to modify the behaviour of a function or class. The way this is achieved is by defining a function (decorator) that returns another function. This sounds complicated, but you will understand everything…

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Michael Krasnov
Michael Krasnov

Written by Michael Krasnov

Software Developer | Writer | Open Source Evangelist

Responses (7)

Write a response