ProgrammingVery hardPython · GATE DA · Advanced

What is printed?

What is printed?
class Meta(type):
    def __new__(m, name, bases, d):
        d['tag'] = name.lower()
        return super().__new__(m, name, bases, d)
class A(metaclass=Meta):
    pass
class B(A):
    pass
print(A.tag, B.tag, type(B).__name__, isinstance(B(), A))
  1. A. a a Meta True
  2. B. a b Meta True
  3. C. a b type True
  4. D. a b Meta False

Correct answer: B. a b Meta True

A metaclass is inherited: creating B calls Meta.__new__ again with name 'B', so B.tag is 'b' (not inherited from A), type(B) is Meta, and instances of B are still instances of A.

More Python Programming questions

Exams that ask this topic