1. Home
  2. Data Science
  3. Python
  4. What happens when you open an existing file with mode 'w'…

Added 25 Nov 2026

What happens when you open an existing file with mode 'w' in Python?

  1. Its content is erased Correct answer
  2. It is appended to
  3. It opens read-only
  4. It raises an error

Correct answer

A. Its content is erased

7 views

MCQSEXAM

Explanation

'w' truncates the file to zero length.

Reference

Asked in: Python Interview File Handling

https://docs.python.org/3/tutorial/inputoutput.html

Preparing for an exam?

Doubts & discussion

Not sure why the answer is A? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More Python MCQs

Practise all Python MCQs

Similar MCQs