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: May 28, 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

Approach Solution - 1

To correctly match the methods and their functionalities from List-I and List-II, let's analyze each: 

  • (A) readline(): This method reads a single line from a file. Thus, it matches with (II).
  • (B) writelines(): This method writes a sequence of strings to a file. Thus, it matches with (I).
  • (C) seek(): This method moves the file pointer to a specified position within the file. Thus, it matches with (IV).
  • (D) flush(): This method forces any buffered output to be written to the file. Thus, it matches with (III).
List-IList-II
(A) readline()(II) Reads a single line from the file
(B) writelines()(I) Writes a sequence of strings to the file
(C) seek()(IV) Moves the file pointer to the specified position
(D) flush()(III) Force any buffered output to be written to the file

The correct answer is: (A) - (II), (B) - (I), (C) - (IV), (D) - (III)

Was this answer helpful?
0
0
Hide Solution
collegedunia
Verified By Collegedunia

Approach Solution -2

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