1.

What is the use of seek() method in files?(a) sets the file’s current position at the offset(b) sets the file’s previous position at the offset(c) sets the file’s current position within the file(d) none of the mentionedThis question was addressed to me during an interview.My doubt stems from Files topic in portion Regular Expressions and Files of Python

Answer»

Correct choice is (a) sets the file’s current position at the OFFSET

Easiest explanation - Sets the file’s current position at the offset. The method SEEK() sets the file’s current position at the offset.

Following is the syntax for seek() method:

fileObject.seek(offset[, whence])

Parameters

offset — This is the position of the read/write pointer WITHIN the file.

whence — This is OPTIONAL and defaults to 0 which means absolute file positioning, other values are 1 which means seek relative to the current position and 2 means seek relative to the file’s end.



Discussion

No Comment Found

Related InterviewSolutions