Skip to main contentSkip to solution

Which of the following methods is used to position a file object to a specific position in a file?

Solution

✅ Correct Option: 4

The seek() method moves the file pointer to a given position. Its syntax is f.seek(offset, whence), where offset is the number of bytes to move and whence is the reference point (0 = start of file, 1 = current position, 2 = end of file).


Option 1: tell() only returns the current position of the file pointer. It does not move it.

Options 2 and 3: peep() and move() are not file object methods in Python.

Keyboard Shortcuts

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