Test Index
File Handling in Python
© examsnet.com
Question : 17 of 37
Marks:
+1,
-0
Consider the following Python statement :
F=open('CONTENT.TXT')Which of the following is an invalid statement in Python ?[CBSE 2024 Set 4]
Solution:
Concept:
F.seek(offset, reference_point) moves the file pointer. The reference point (whence) can only be:0: from the beginning of the file (default)1: from the current position2: from the end of the fileExplanation:F.seek(1,0): 1 byte from the beginning, valid.F.seek(0,1): stay at the current position, valid.F.seek(0,2): go to the end of the file, valid.F.seek(0,-1): -1 is not a valid reference point, so it raises ValueError.Answer:Option C (F.seek(0,-1))© examsnet.com
Go to Question: