Skip to main contentSkip to solution

How do you move the file pointer to the 10th10^{\text{th}} byte from the beginning of a file in Python?

Solution

✅ Correct Option: 1

The syntax is file.seek(offset, whence). Here offset = 10 is the number of bytes to move, and whence = 0 means counting from the beginning of the file, so the pointer lands on byte 10 from the start.

Other values of whence: 1 is the current position, and 2 is the end of the file.


Option 2: the arguments are swapped, so it gives offset 0 and whence 10, which is invalid.

Option 3: file objects have no move() method.


We believe the answer could be Option 4 as well, since whence defaults to 0 in Python, so file.seek(10) behaves exactly like file.seek(10, 0). However, NTA's final answer key (after all challenges) says Option 1.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question