ProgrammingVery hardGATE CS · Product-company placement
What is printed?
What is printed?
class Stack(list):
def push(self, v):
self.append(v)
return self
s = Stack()
s.push(1).push(2)
t = s + [3]
print(type(t).__name__, s, isinstance(s, list), s == [1, 2])- A. Stack [1, 2] True True
- B. list [1, 2] True False
- C. list [1, 2] True True
- D. Stack [1, 2, 3] True True
Correct answer: C. list [1, 2] True True
Inherited list operations like + return a plain list, not the subclass. A Stack compares equal to a list with the same items.
More Python Programming questions
- What is printed? (Output lines are shown separated by " / ".) python def f(, a, b=2): return a - b def g(a, b=2, /): return a - b…
- What is printed? python def outer(fn): def w(a, k): return fn(a, k) 2 return w class C: @outer def val(self, x): return x + 1 @property…
- What is printed? python def log(prefix): def deco(fn): def w(a): return prefix + str(fn(a)) return w return deco @log("A:") @log("B:") def…
- What is printed? python import functools def once(fn): done = [] @functools.wraps(fn) def w(a): if not done: done.append(fn(a)) return…
- What is printed? python class A: def init(self): print("A", end=" ") class B(A): def init(self): print("B", end=" ") class C(B): pass C()…
- What is printed? python class A: def f(self): return "A" class B(A): def f(self): return "B" + super().f() class C(A): def f(self): return…