ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
def outer(fn):
    print("deco", end=" ")
    return fn
@outer
def g():
    print("g", end=" ")
print("start", end=" ")
g(); g()
  1. A. start deco g g
  2. B. start deco g deco g
  3. C. deco start g g
  4. D. deco start g deco g

Correct answer: C. deco start g g

A decorator runs once, at function-definition time (when the def statement executes), not on each call; outer returns fn unchanged, so later calls just print g.

More Python Programming questions

Exams that ask this topic