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.
Answer checked How we write and check questions
Discussion