Practice mode Python

What does opening an existing file with mode ‘w’ do to its current contents?

Correct answer D. The contents are erased because the file is truncated

Explanation

Mode 'w' opens a file for writing and truncates it first, so all previous content is lost as soon as the file is opened, even before anything is written. Use 'a' to append, or 'r+' to read and write without truncating.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.