ProgrammingHardAccenture pattern

What is printed?

What is printed?
def deco(f):
    def wrapper(*a, **k):
        wrapper.calls += 1
        return f(*a, **k)
    wrapper.calls = 0
    return wrapper
@deco
def h():
    return 1
h(); h(); h()
print(h.calls)
  1. A. 0
  2. B. 1
  3. C. 3
  4. D. AttributeError

Correct answer: C. 3

wrapper.calls is a plain function attribute attached to the wrapper object itself, which h now refers to. Each call increments it, so after three calls h.calls is 3.

More Python Programming questions

Exams that ask this topic