Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Challenge: Write Your First Decorator | Decorator Fundamentals
Python Decorators Explained

bookChallenge: Write Your First Decorator

You have already learned that a decorator in Python is a function that takes another function as its argument and returns a new function that can add extra behavior before or after the original function runs. Decorators are applied using the @decorator_name syntax directly above the function definition. This allows you to modify or enhance functions in a reusable way, without changing their actual code.

Tâche

Swipe to start coding

Create a decorator called print_status that wraps any function so that it prints "Function started" before calling the function and "Function ended" after the function finishes. The decorator must work with functions that accept any number of arguments.

Solution

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 1. Chapitre 3
single

single

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

close

bookChallenge: Write Your First Decorator

Glissez pour afficher le menu

You have already learned that a decorator in Python is a function that takes another function as its argument and returns a new function that can add extra behavior before or after the original function runs. Decorators are applied using the @decorator_name syntax directly above the function definition. This allows you to modify or enhance functions in a reusable way, without changing their actual code.

Tâche

Swipe to start coding

Create a decorator called print_status that wraps any function so that it prints "Function started" before calling the function and "Function ended" after the function finishes. The decorator must work with functions that accept any number of arguments.

Solution

Switch to desktopPassez à un bureau pour une pratique réelleContinuez d'où vous êtes en utilisant l'une des options ci-dessous
Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 1. Chapitre 3
single

single

some-alt