LearnFrenzy
Sign in Take a free test

Decorators · Exercise 1 of 4

Decorators Decorators MCQ

  • 15 questions
  • Page 2 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

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.

Question 11 Easy

Which of these is NOT a decorator in the standard library?

A @property
B @functools.lru_cache
C @staticmethod
D @override_all
Question page & discussion
Question 12 Easy

A wrapper calls func(*args) but does not return its value. What does the decorated function return?

A The original result
B The wrapper itself
C None
D An error
Question page & discussion
Question 13 Hard

With functools.wraps used, how can you call the undecorated function?

A f.original(...)
B undecorate(f)(...)
C f.__wrapped__(...)
D It is impossible
Question page & discussion
Question 14 Hard

A decorator has count = 0 and the wrapper does count += 1. What is needed for this to work?

A global count inside the decorator
B nonlocal count inside the wrapper
C Nothing
D Making count a parameter of the wrapper
Question page & discussion
Question 15 Easy

Which task is a typical use of a decorator?

A Declaring a variable's type
B Importing a module
C Defining a loop
D Logging every call of several functions
Question page & discussion
Up next · Exercise 2Predict the Output15 questions

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links