- The
withkeyword lets you choose which application to open the file in. - The
withkeyword acts like aforloop, and lets you access each line in the file one by one. - There is no benefit to using the
withkeyword for opening a file in Python. - When you open a file using the
withkeyword in Python, Python will make sure the file gets closed, even if an exception or error is thrown.
Correct Answer:
- When you open a file using the
withkeyword in Python, Python will make sure the file gets closed, even if an exception or error is thrown.
7. Input and Output — Python 3.10.2 documentation
https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files