ProgrammingVery hardGATE CS · Product-company placement

What is printed?

What is printed?
def inner():
    a = yield "x"
    b = yield "y"
    return (a, b)
def outer():
    r = yield from inner()
    yield r
o = outer()
print(next(o), o.send(1), o.send(2))
  1. A. x y (1, 2)
  2. B. x y (None, 2)
  3. C. x 1 2
  4. D. x y None

Correct answer: A. x y (1, 2)

yield from forwards send() to the inner generator: a = 1, b = 2. inner's return value (1, 2) becomes the value of the yield from expression, which outer then yields.

More Python Programming questions

Exams that ask this topic