Intermediate Python
Q65 / 101

What is the purpose of __enter__ and __exit__ methods?

Correct! Well done.

Incorrect.

The correct answer is B) They implement the context manager protocol used by the with statement

B

Correct Answer

They implement the context manager protocol used by the with statement

Explanation

__enter__ is called when entering a with block; __exit__ is called when leaving (even on exception), handling teardown and optional exception suppression.

Progress
65/101