Which of these is NOT a decorator in the standard library?
The others are used every day; @override_all does not exist.
Decorators · Exercise 1 of 4
Fifteen multiple-choice questions on Python decorators: the @ syntax, wrappers, functools.wraps, when decorators run, arguments, stacking, closures and built-in decorators. Pick an option to check your answer instantly.
Which of these is NOT a decorator in the standard library?
The others are used every day; @override_all does not exist.
A wrapper calls func(*args) but does not return its value. What does the decorated function return?
Write return func(*args, **kwargs).
With functools.wraps used, how can you call the undecorated function?
Useful in tests to bypass caching or access checks.
A decorator has count = 0 and the wrapper does count += 1. What is needed for this to work?
Without nonlocal, count += 1 makes count local to the wrapper and raises UnboundLocalError.
Which task is a typical use of a decorator?
Cross-cutting concerns – logging, timing, caching, authorisation, retries – are what decorators are for.
Timed online tests with instant scores and explanations.