Intermediate Python
Q85 / 101

What is the purpose of contextlib.contextmanager?

Correct! Well done.

Incorrect.

The correct answer is B) A decorator that turns a generator function into a context manager, using yield to separate __enter__ and __exit__ behavior

B

Correct Answer

A decorator that turns a generator function into a context manager, using yield to separate __enter__ and __exit__ behavior

Explanation

@contextmanager def managed(): setup(); try: yield value; finally: teardown() creates a context manager without writing a class.

Progress
85/101