Loading section...
Decorators
Concepts: pyDecorators
Decorators let you extend function behavior without modifying the original code. They are a powerful tool for cross-cutting concerns like logging and timing. The Wrapper Pattern A decorator is a function that takes another function and returns an enhanced version. The wrapper function adds behavior before or after calling the original. Using the @ Syntax Decorators can be stacked by applying multiple @ lines above a function. They are applied from bottom to top, so the decorator closest to the function runs first. Real-world frameworks like Flask and Django use decorators extensively to register routes, enforce authentication, and cache expensive results.