Test Index
File Handling in Python
© examsnet.com
Question : 32 of 37
Marks:
+1,
-0
Which of the following modes in Python creates a new file, if file does not exist and overwrites the content, if the file exists ?
[CBSE 2023 Compartment]
Solution:
Concept:File modes:
r read only (file must exist), r+ read and write (file must exist), w write, a append.Explanation:w mode creates the file if it does not exist, and if it exists, its old content is erased (overwritten).a mode also creates a missing file, but it keeps the old content and adds new data at the end. r and r+ give an error if the file does not exist.Answer:Option C (w)© examsnet.com
Go to Question: