A programmer wants to add a new line of text to the end of an existing file…
2026
A programmer wants to add a new line of text to the end of an existing file named logs.txt without deleting the current content. Which mode should they use in the open() function?
- A.
r
- B.
w
- C.
a
- D.
x
Attempted by 163 students.
Show answer & explanation
Correct answer: C
To add a new line to the end of an existing file without deleting current content, use mode 'a' (append). The open() function with mode 'a' allows writing to the end of the file while preserving existing data. Mode 'r' is for reading only, and mode 'w' truncates the file before writing.