Question:

How do you move the file pointer to the 10th byte from the beginning of a file in Python?

Show Hint

Remember the three values of the whence parameter:
- 0 = Start of file.
- 1 = Current position.
- 2 = End of file.
Updated On: Jun 11, 2026
  • file.seek(10, 0)
  • file.seek(0, 10)
  • file.move(10, 0)
  • file.seek(10)
Show Solution
collegedunia
Verified By Collegedunia

The Correct Option is A

Solution and Explanation


Step 1: Understanding the Question:

The question asks for the correct Python code syntax to position a file's read/write pointer to exactly the 10th byte relative to the start of the file.

Step 2: Python's seek() Syntax:

Python's file objects utilize the seek() method to move the file pointer.
- Syntax: file_object.seek(offset, whence)
- offset: The number of bytes to move the pointer.
- whence: The starting reference point. It can take three values:
- 0 (default): Relative to the beginning of the file.
- 1: Relative to the current pointer position.
- 2: Relative to the end of the file.

Step 3: Detailed Explanation:

- To position the file pointer at the 10th byte from the beginning of the file, we require an offset of 10 and a reference point (whence) of 0 (representing the file start).
- This translates to the code: file.seek(10, 0). This is represented by Option (A).
- Option (B) file.seek(0, 10) is syntactically invalid because 10 is not a valid parameter value for whence.
- Option (C) uses a non-existent method move().
- Option (D) file.seek(10) is also technically correct in standard Python because whence defaults to 0 when omitted. However, standard academic curricula (like CBSE and CUET) explicitly teach file.seek(offset, 0) to introduce reference-based seek positions. Thus, option (A) is the most complete, explicit, and formally correct choice in the context of this exam.

Step 4: Final Answer:

The correct method to position the pointer to the 10th byte from the beginning is file.seek(10, 0).
Hence, option (A) is the correct choice.
Was this answer helpful?
0
0