This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Why is it a best practice to open files using the with statement?
with
It makes the file open faster.
It automatically closes the file when the block finishes, even if an error occurs.
It converts the file contents into a list of strings.
Which mode opens a file for writing and erases any existing content?
"r"
"a"
"w"
What does the .readlines() method return?
.readlines()
A single string containing the entire file.
A list of strings, one for each line in the file.
The number of lines in the file.
You must answer all questions before checking your work.
Was this page helpful?
Need help with this topic?
Want to try using Ask Learn to clarify or guide you through this topic?