Question:

Match List-I with List-II:
List-IList-II
(A) f.seek(-10,1)(I) From beginning of file, move 10 bytes forward
(B) f.seek(10,1)(II) From current position, move 10 bytes backward
(C) f.seek(10)(III) From current position, move 10 bytes forward
(D) f.seek(-10,2)(IV) From end of the file, move 10 bytes backward

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

The Correct Option is D

Approach Solution - 1

Solution: The task involves matching function calls related to file seeking with their respective descriptions. In Python, the seek() method is used with a file object to change the file's current position. The method signature is f.seek(offset, whence) where offset is the number of bytes to move and whence determines the reference position.

  • whence=0: Move the pointer from the beginning of the file. This is the default. (e.g., f.seek(10))
  • whence=1: Move the pointer from the current file position. (e.g., f.seek(10,1) or f.seek(-10,1))
  • whence=2: Move the pointer from the end of the file. (e.g., f.seek(-10,2))

Now, match the statements to their meanings:

(A) f.seek(-10,1)(II) From current position, move 10 bytes backward
(B) f.seek(10,1)(III) From current position, move 10 bytes forward
(C) f.seek(10)(I) From beginning of file, move 10 bytes forward
(D) f.seek(-10,2)(IV) From end of the file, move 10 bytes backward

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

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

Approach Solution -2

 

CodeInterpretationCorrect Match
f.seek(-10,1)From current position, move 10 bytes backward(II)
f.seek(10,1)From current position, move 10 bytes forward(III)
f.seek(10)From beginning of file (default), move 10 bytes forward(I)
f.seek(-10,2)From end of file, move 10 bytes backward(IV)

Correct Matching:

  • (A) - (II)
  • (B) - (III)
  • (C) - (I)
  • (D) - (IV)
Was this answer helpful?
0
0