ProgrammingVery hardGATE CS · Product-company placement
What is printed?
What is printed?
class X: pass
class Y: pass
class A(X, Y): pass
class B(Y, X): pass
try:
class C(A, B): pass
print("ok")
except TypeError:
print("TypeError")- A. ok
- B. ok C A B X Y
- C. AttributeError
- D. TypeError
Correct answer: D. TypeError
A requires X before Y and B requires Y before X, so no consistent C3 order exists for C(A, B); class creation raises TypeError.
More Python Programming questions
- What is printed? python class Base: def init(self): print("Base", end=" ") class L(Base): def init(self): print("L", end=" ")…
- 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)