ProgrammingHardAccenture pattern

What is printed?

What is printed?
class F:
    @staticmethod
    def add(a, b):
        return a + b
    @classmethod
    def create(cls):
        return cls()
print(F.add(2, 3))
f = F()
print(f.add(1, 1))
  1. A. 5 2
  2. B. 5 TypeError
  3. C. TypeError 2
  4. D. 5 5

Correct answer: A. 5 2

A staticmethod receives no implicit self or cls, whether called on the class or an instance, so both F.add(2,3) and f.add(1,1) just run the plain function: 5 and 2.

More Python Programming questions

Exams that ask this topic