ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
def g():
    print("start", end=" ")
    yield 1
    print("mid", end=" ")
    yield 2

it = g()
print("made", end=" ")
print(next(it), end=" ")
print(list(it))
  1. A. made start 1 mid [2]
  2. B. start made 1 mid [2]
  3. C. made start 1 mid [1, 2]
  4. D. made start mid 1 [2]

Correct answer: A. made start 1 mid [2]

Calling g() only creates a generator; no body code runs, so "made" is printed first. next(it) runs up to the first yield, printing "start" and producing 1. list(it) resumes after that yield, printing "mid", collects 2, then the generator ends. The 1 was already consumed, so the list is [2].

More Python Programming questions

Exams that ask this topic