Question:

Consider the following Python statement: 
F = open('CONTENT.TXT')
Which of the following is an invalid statement in Python? 
 

Show Hint

Always use valid whence} values (0, 1, or 2) with F.seek()} to avoid runtime errors.
Updated On: Jan 21, 2025
  • F.seek(1, 0)
     

  • F.seek(0, 1)
     

  • F.seek(0, -1)
     

  • F.seek(0, 2)
     

Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is C

Solution and Explanation

The seek() method in Python is used to change the file’s current position. 
It takes two arguments: 
1. offset: The position (in bytes) to move the file pointer to. 
2. whence: The reference point for offset. 
Valid values for whence are: 
0: Beginning of the file. 
1: Current file position. 
2: End of the file. 
A value of -1 for whence is invalid, making F.seek(0, -1) incorrect.

Was this answer helpful?
0
0

Top Questions on Commands and Requests

View More Questions