ProgrammingVery hardGATE CS · Product-company placement

What is printed?

What is printed?
def outer(fn):
    def w(*a, **k):
        return fn(*a, **k) * 2
    return w
class C:
    @outer
    def val(self, x):
        return x + 1
    @property
    @outer
    def p(self):
        return 5
c = C()
print(c.val(1), c.p, C.val.__name__)
  1. A. 4 10 val
  2. B. 4 10 w
  3. C. 2 10 w
  4. D. 4 5 w

Correct answer: B. 4 10 w

The wrapper is an ordinary function stored on the class, so it binds like a method: self is passed through *a. property wraps the already-decorated getter, doubling 5. Without wraps the name is w.

More Python Programming questions

Exams that ask this topic