Why is the with statement recommended when working with files in Python?
Correct answer
C. It closes the file automatically
11 views
C. It closes the file automatically
11 views
The context manager ensures the file is closed even if an error occurs.
Asked in: Python Interview File Handling
https://docs.python.org/3/tutorial/inputoutput.htmlNot sure why the answer is C? Ask here and get an explanation.