Question:medium

Sequence the steps to append data to an existing file and then read the entire file:
(A) Open the file in a+ mode.
(B) Use the read() method to output the contents.
(C) Use the write() or writelines() method to append data.
(D) Seek to the beginning of the file.

Show Hint

When appending and reading a file, always make sure to move the file pointer to the beginning using \texttt{seek(0)} before reading the file after appending data.
Updated On: Feb 16, 2026
  • (A), (C), (D), (B)
  • (A), (B), (C), (D)
  • (B), (A), (C), (D)
  • (C), (B), (D), (A)
Show Solution

The Correct Option is A

Solution and Explanation

Step 1: Open the file in a+ mode.
To append data to an existing file and then read it, open the file using \texttt{a+} mode. This mode facilitates both appending and reading operations.
Step 2: Append data using write() or writelines().
With the file open in \texttt{a+} mode, employ the \texttt{write()} or \texttt{writelines()} method to append data.
Step 3: Seek to the beginning of the file.
Post-appending, reposition the file pointer to the file's start using \texttt{seek(0)}. This action enables reading from the outset.
Step 4: Read the file contents using read().
Finally, utilize the \texttt{read()} method to retrieve and display the file's contents from the beginning.
Step 5: Conclusion.
The correct order of operations is as follows: 1. (A) Open the file → 2. (C) Append data → 3. (D) Seek to beginning → 4. (B) Read contents.
Final Answer: \[\boxed{\text{The correct sequence is (A), (C), (D), (B).}}\]
Was this answer helpful?
0


Questions Asked in CUET (UG) exam