ProgrammingVery hardGATE CS · Product-company placement
What is printed?
What is printed?
def g():
try:
yield 1
except GeneratorExit:
print("exit", end=" ")
yield 2
it = g()
next(it)
try:
it.close()
except RuntimeError:
print("RuntimeError")- A. exit
- B. exit RuntimeError
- C. RuntimeError
- D. exit 2
Correct answer: B. exit RuntimeError
close() throws GeneratorExit into the generator. If the generator responds by yielding another value instead of finishing, close() raises RuntimeError ('generator ignored GeneratorExit').
More Python Programming questions
- What is printed? (Output lines are shown separated by " / ".) python it = iter([1, 2, 3, 4, 5, 6]) print([(a, b) for a, b in zip(it, it)]…
- What is printed? python s = {1, 2, 3} t = {3, 4} print(s | t, s & t, s - t, s ^ t, s >= {1, 2})
- What is printed? python a = {1, 2} b = a a |= {3} c = frozenset(a) a = a | {4} print(b, c, a, type(c | {9}).name)
- What is printed? python s = set() s.add((1, 2)) s.add((2, 1)) try: s.add([1]) except TypeError: s.add(frozenset([1]))…
- What is printed? python d = {"a": 1, "b": 2, "c": 3} del d["a"] d["a"] = 4 d.pop("b") d["b"] = 5 print(list(d.items()), next(iter(d))…
- What is printed? python class Key: def init(self, v): self.v = v def hash(self): return hash(self.v) def eq(self, o): return self.v == o.v…