Predict the Decorator Output
Intermediate · Predict the output · from Python Decorators Explained: A Step-by-Step Guide
From the lesson: What Is the Basic Decorator Pattern?
A decorator is a function that takes a function as input, creates a wrapper function that adds behavior, and returns the wrapper. Here's the template:
Read this part of the lessonWhat does this code print? Pay attention to the order of execution.
def shout(func):
def wrapper(*args, **kwargs):
result = func(*args, **kwargs)
return result.upper()
return wrapper
@shout
def greet(name):
return f'hello, {name}'
print(greet('world'))Write one print() statement that produces the exact same output.
# What does the decorated function print?
print("?")
More Decorator exercises
- Write a Logging DecoratorAdvanced
- Write a Repeat DecoratorAdvanced
- Predict Stacked Decorator OutputAdvanced
- Write a Validation DecoratorAdvanced
- Write a Retry DecoratorAdvanced
- Fix the Broken DecoratorIntermediate
- Build a Simple Cache DecoratorAdvanced
All Python exercises · 50 practice problems · Advanced Python quiz