Skip to main contentSkip to solution

The seek() method can be used to position the file object at a particular position in a file depending upon the offset. What will be the offset position, if someone wants to write at the current position of the file?

Solution

✅ Correct Option: 2

In Python, seek(offset, whence) takes a second argument that sets the reference point for the offset. The value 11 means the current file position, so f.seek(0, 1) keeps the file object where it is and writing continues from there.


Option 1 (00): the beginning of the file, so writing would start from the start.

Option 3 (22): the end of the file, which is used to append.

The values for whence are 00 (start), 11 (current) and 22 (end). Remember them as 0-1-2 for start-current-end.

Keyboard Shortcuts

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