ProgrammingHardGATE CS · Product-company placement
What is printed?
What is printed?
def g():
print("a", end=" ")
x = yield
print("b", x, end=" ")
yield x * 2
it = g()
print(it.send(None), end=" ")
print(it.send(3))- A. a b 3 6
- B. None a b 3 6
- C. a None b None TypeError
- D. a None b 3 6
Correct answer: D. a None b 3 6
send(None) starts the generator: it prints a and stops at the bare yield, which yields None. send(3) resumes with x = 3, prints b 3, and yields 6.
More Python Programming questions
- What is printed? python def g(): try: yield 1 except GeneratorExit: print("exit", end=" ") yield 2 it = g() next(it) try: it.close()…
- 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))…