CodeX
Published in

CodeX

Python Decorators Made Simple

What are decorators? How to use them? When to use them?

Python decorators provide a way to extend the functionality of a function, method, or class outside of it.

Here is an example of decorating divide function with functionality to check that the divisor is not 0.

@zero_guard
def divide(x, y):
return x / y

--

--

Everything connected with Tech & Code. Follow to join our 1M+ monthly readers

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Artturi Jalli

I built a blog from 0 to 500k+ monthly visits in 16 months without SEO.