← All topics
Quiz: Python Decorators: questions with answers
10 questions, each with the answer and a short explanation.
Take the timed quiz + get a certificate →- Q1. What is a decorator in Python?
- Q2. @timer above def load(): is the same as which line?
- Q3. What does this print? (code)
- Q4. What does this print? (code)
- Q5. Why should a wrapper use args, kwargs?
- Q6. What does @functools.wraps(func) do?
- Q7. How many nested functions does a decorator with arguments, like @repeat(3), usually have?
- Q8. What does this print? (code)
- Q9. Which standard-library decorator remembers results so repeated calls are fast?
- Q10. Which of these is a typical real use of decorators?