ProgrammingVery hardGATE CS · Product-company placement

What is printed?

What is printed?
calls = []
def trace(fn):
    calls.append(fn.__name__)
    return fn
class C:
    @trace
    def m(self): pass
    @staticmethod
    @trace
    def s(): pass
    @property
    @trace
    def p(self): return 1
print(calls, C().p, type(C.__dict__["s"]).__name__)
  1. A. ['m', 's', 'p'] 1 function
  2. B. ['m', 'p'] 1 staticmethod
  3. C. ['m', 's', 'p'] 1 staticmethod
  4. D. ['m', 's', 'p'] <bound method> staticmethod

Correct answer: C. ['m', 's', 'p'] 1 staticmethod

trace runs once per decorated def, in class-body order, on the plain function. C.__dict__ keeps the staticmethod object itself, while property makes C().p return the value 1.

More Python Programming questions

Exams that ask this topic