ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
def g():
    x = yield 1
    yield x * 2

it = g()
print(next(it), it.send(5))
  1. A. 1 10
  2. B. 1 2
  3. C. TypeError
  4. D. 1 None

Correct answer: A. 1 10

next(it) runs up to the first yield and returns 1. send(5) resumes the generator, makes that paused yield expression evaluate to 5 (so x = 5), and runs to the next yield, which produces 10.

More Python Programming questions

Exams that ask this topic