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))
  1. A. a b 3 6
  2. B. None a b 3 6
  3. C. a None b None TypeError
  4. 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

Exams that ask this topic