Back to feed

Primer on Python Decorators

Real Python

EDITOR BRIEF

This tutorial explains what Python decorators are and how to define and use them. It also shows how decorators can improve code readability and reuse, and how they work internally. Readers are encouraged to practice writing their own decorators.

INSIGHTS

Decorators are a useful Python pattern for adding behavior without repeating code. Try writing a simple decorator that logs a function call, then test it on a few functions.

CodeFriends courses that build on this story. Practice in the browser with nothing to install.

COMMENTS

0/40
0/2000

Loading comments…