Question:

Match List-I with List-II:
List-IList-II
(A) readline()(I) Writes a sequence of strings to the file
(B) writelines()(II) Reads a single line from the file
(C) seek()(III) Force any buffered output to be written to the file
(D) flush()(IV) Moves the file pointer to the specified position

Updated On: Mar 29, 2025
  • (A) - (I), (B) - (II), (C) - (III), (D) - (IV)
  • (A) - (II), (B) - (I), (C) - (IV), (D) - (III)
  • (A) - (II), (B) - (I), (C) - (III), (D) - (IV)
  • (A) - (III), (B) - (IV), (C) - (I), (D) - (II)
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is B

Solution and Explanation

Let's match the functions with their descriptions:

Therefore, the correct matching is:
(A) - (II)
(B) - (I)
(C) - (IV)
(D) - (III)

This corresponds to option (2).

Additional Context:

  • File Operation Functions:
  • readline() (A): (II) Reads single line
  • Stops at newline character (\n)
  • Returns empty string at EOF
  • seek() (B): (IV) Moves file pointer
  • Syntax: file.seek(offset, whence)
  • whence: 0 (start), 1 (current), 2 (end)
  • Other Functions Mentioned:
  • writelines(): Writes list of strings
  • flush(): Forces buffer write to disk
  • Common File Handling Pattern:with open("file.txt", "r") as f:    line = f.readline()  # (A)-(II)    f.seek(0)  # (B)-(IV)    .
Was this answer helpful?
0
0