What is the purpose of seek() function?

 

Answer:

The seek( ) method is used to position the file object at a particular position in a file. 

The syntax of seek() is: 

file_object.seek(offset , [reference_point])

In the above syntax, 

  • offset is the number of bytes by which the file object is to be moved
  • reference_point indicates the starting position of the file object . That is, with reference to which position, the offset has to be counted. 

It can have any of the following values:

  • 0 - beginning of the file 
  • 1 - current position of the file 
  • 2 - end of file  
  • Default value of reference_point is 0.
Go Ad-free
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science and Computer Science at Teachoo