Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumPythongenerators and yieldSingle-choice MCQ

A generator is paused on its first yield. What happens when you call g.close() if the generator wraps its yield in a try/finally?

def gen(): try: yield 1 yield 2 finally: print("cleanup") g = gen() next(g) g.close()