Question
Why is `with open(‘data.txt’) as f:` preferred for many file-reading tasks?
Select an option. Your answer will be checked instantly.
Correct Answer: A. It automatically manages closing the file when the block ends
Explanation:
A context manager handles resource cleanup even when an error occurs inside the block. This reduces the risk of leaving the file open unintentionally.
Leave a Reply