ProgrammingVery hardGATE CS · Product-company placement

What is printed?

What is printed?
def g():
    yield 1
    raise StopIteration
try:
    print(list(g()))
except RuntimeError as e:
    print("RuntimeError")
  1. A. [1]
  2. B. []
  3. C. RuntimeError
  4. D. [1, None]

Correct answer: C. RuntimeError

Since PEP 479 (Python 3.7+), a StopIteration raised inside a generator body is converted to RuntimeError, so list() does not silently stop; the RuntimeError propagates.

More Python Programming questions

Exams that ask this topic