Which of the following functions changes the position of file pointer and returns its new position?
a.flush()
b.tell()
c.seek()
d.offset()
Answer
Answer by student:
c. seek()
Detailed answer by teachoo:
A file pointer is a variable that holds the current position of the file cursor, which is used to read or write data in a file.
Checking the options:
- Option a: The flush() function flushes the internal buffer of the file object, which means it writes any unwritten data to the file. This function does not change the position of the file pointer, nor does it return its new position, so it is incorrect .
- Option b: The tell() function returns the current position of the file pointer as an integer value. This function does not change the position of the file pointer, but only reports it, so it is incorrect .
- Option c: The seek() function changes the position of the file pointer and returns its new position as an integer value. This function can move the file pointer to any location in the file, so it is correct .
- Option d: The offset() function is not a valid function in Python, so it is incorrect .
So, the correct answer is c. seek().