Login to manage your account

Please enter a valid email address.
Forgot Password?
Please enter a valid password.
OR

Don't have an account yet? Sign up

What does the with statement provide?

  1. A A loop construct
  2. B Automatic setup and cleanup through the context manager protocol
  3. C Conditional execution
  4. D Exception suppression
Answer

Automatic setup and cleanup through the context manager protocol

The __enter__ and __exit__ methods guarantee cleanup, so a file is closed even if an exception is raised inside the block.

All Python MCQs

Login to manage your account

Please enter a valid email address.
Forgot Password?
Please enter a valid password.
OR

Don't have an account yet? Sign up as