Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Challenge: Write Your First Decorator | Decorator Fundamentals
Quizzes & Challenges
Quizzes
Challenges
/
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.

Завдання

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.

Рішення

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 3
single

single

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

Suggested prompts:

Can you give me an example of a simple decorator?

What are some common use cases for decorators in Python?

How do I write my own custom decorator?

close

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.

Завдання

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.

Рішення

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 3
single

single

some-alt