Which of the following functions returns the current position of the file pointer in a file?

a) seek( ) 

b) tell( ) 

c) read( ) 

d) readline( )

Answer:

Answer by student

b) tell( )

Detailed answer by teachoo

-lock-

File pointer functions are methods that manipulate the position of the file pointer, which is a cursor that indicates where the next read or write operation will take place in a file. There are two main file pointer functions in Python: seek( ) and tell( ).

Now, let’s go through each of the options and see why they are correct or incorrect.

a) seek( ): This option is incorrect because seek( ) is a function that sets the position of the file pointer to a given specific position. 

b) tell( ): This option is correct because tell( ) is a function that returns the current position of the file pointer in a file . It takes no parameters and returns an integer value that represents the number of bytes from the start of the file. 

c) read( ): This option is incorrect because read( ) is a function that reads data from a file and returns it as a string or bytes object.

d) readline( ): This option is incorrect because readline( ) is a function that reads one line from a file and returns it as a string or bytes object. 

So, the correct answer is b) tell( ).

-endlock-

Remove Ads
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh is an IIT Kanpur graduate and has been teaching for 16+ years. At Teachoo, he breaks down Maths, Science and Computer Science into simple steps so students understand concepts deeply and score with confidence.

Many students prefer Teachoo Black for a smooth, ad-free learning experience.