Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Conditional Decorator | Mastering Python Decorators
Functional Programming Concepts in Python
Section 4. Chapter 4
single

single

bookChallenge: Conditional Decorator

Swipe to show menu

Task

Swipe to start coding

Write a parameterized decorator that only allows a function to run if a given argument is True.

  • If the parameter to the decorator is True, call the decorated function and return its result.
  • If the parameter to the decorator is False, do not call the decorated function and return None instead.
  • Do not forget to return decorator and wrapper functions.

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 4. Chapter 4
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

some-alt