Test Index

File Handling in Python Get it on Google PlayDownload on the App Store CBSE Board Videos

© 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 position
2: from the end of the file
Explanation:
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
Advertisements
Go to Question: