ProgrammingHardGATE CS · Product-company placement
What is printed?
What is printed?
class Base:
def __init__(self):
print("Base", end=" ")
class L(Base):
def __init__(self):
print("L", end=" ")
super().__init__()
class R(Base):
def __init__(self):
print("R", end=" ")
class M(L, R):
pass
M()- A. L Base
- B. L R Base
- C. L R
- D. L Base R
Correct answer: C. L R
M's MRO is M, L, R, Base. L's super().__init__() calls the NEXT class in M's MRO, which is R, not Base. R does not call super(), so Base.__init__ never runs.
More Python Programming questions
- What is printed? python class A: x = "A" def get(self): return self.x class B(A): x = "B" b = B() A.x = "A2" b.x = "inst" del b.x…
- What is printed? python class Meta(type): def call(cls, a): print("meta", end=" ") return super().call(a) class K(metaclass=Meta): def…
- What is printed? python class K: def new(cls): print("new", end=" ") return 42 def init(self): print("init", end=" ") r = K() print(r)
- What is printed? python def f(args): args += (99,) return args t = (1, 2) print(f(t), t, f(t))
- What is printed? python first, mid, last = "abcde" (a, b), rest = [(1, 2), 3, 4] init, = range(3) print(mid, last, a + b, rest, init)
- What is printed? python def f(a, b, args, c=0, kw): return a, b, args, c, kw print(f(1, [2, 3, 4], c=5, d=6))