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?

  1. A.

    r

  2. B.

    w

  3. C.

    a

  4. 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.

Explore the full course: Rssb Senior Computer Instructor