🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now →
Menu

Categories

Python Intermediate

What is Decorator?

A function that modifies or extends the behavior of another function or class without changing its source code.

Decorators use the @decorator_name syntax placed above a function definition. They take a function as input and return a modified version. Common uses include logging, authentication checks, caching, and timing execution.

Built-in decorators include @property, @staticmethod, and @classmethod. Popular third-party decorators include @app.route (Flask) and @login_required (Django).