Skills101
← All practice quizzes

Quiz: Python Decorators

5 questions · new set on every retakeNo time limitPass: 60%+10 XP on first pass

Decorators add logging, counting, checks or caching to a function without changing its code. Build one step by step, then learn functools.wraps, decorators with arguments and stacking.

Log in to take the quiz

Free account · see your score, answers and explanations, earn XP

  1. Question 1

    What is a decorator in Python?

  2. Question 2

    @timer above def load(): is the same as which line?

  3. Question 3

    What does this print?

    def deco(f):
        def w():
            return f() * 2
        return w
    @deco
    def five():
        return 5
    print(five())
    
  4. Question 4

    What does this print?

    def deco(f):
        def w():
            f()
        return w
    @deco
    def get():
        return 7
    print(get())
    
  5. Question 5

    Why should a wrapper use *args, **kwargs?

🎯 Today’s placement challenge — 10 questions, no login. Can you score 10/10?Take today’s challenge →