Test Index
File Handling in Python
© examsnet.com
Question : 23 of 37
Marks:
+1,
-0
Assertion (A): If numeric data are to be written to a text file, the data needs to be converted into a string before writing to the file.Reason (R):
write() method takes a string as an argument and writes it to the text file.[CBSE 2024 Compartment]
Solution:
Concept:In an Assertion-Reason question, first check each statement on its own, then ask whether the Reason really explains why the Assertion is true.Explanation:Assertion: A text file stores characters only, so a number must be converted to a string before writing, for example
f.write(str(25)). True.Reason: write() accepts a single string argument and writes it to the file; f.write(25) gives a TypeError. True.The Reason is exactly why the conversion is needed, so R is the correct explanation of A.Answer:Option A (Both Assertion (A) and Reason (R) are true and Reason (R) is the correct explanation of Assertion (A).)© examsnet.com
Go to Question: