ProgrammingHardTCS NQT · Infosys pattern

What is printed?

What is printed?
class A:
    def __call__(self, x):
        return x * 2
a = A()
print(a(5), callable(a))
  1. A. 10 True
  2. B. 5 True
  3. C. 10 False
  4. D. TypeError

Correct answer: A. 10 True

Defining __call__ makes instances of A callable like functions: a(5) invokes __call__(a, 5), returning 10. callable() reports True for any object with __call__.

More Python Programming questions

Exams that ask this topic