Test Index
File Handling in Python
© examsnet.com
Question : 34 of 37
Marks:
+1,
-0
Assertion (A) :
readlines() reads all the lines from a text file and returns the lines along with newline as a list of strings.Reasoning (R) : readline() can read the entire text file line by line without using any looping statements.[CBSE 2023 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: True.
readlines() reads all lines of the file and returns a list of strings, each line keeping its newline character, e.g. ['Hello\n', 'World\n'].Reason: False. readline() reads only one line per call. To read the whole file line by line with it, it must be called repeatedly inside a loop.So (A) is true but (R) is false.Answer:Option C ((A) is true but (R) is false.)© examsnet.com
Go to Question: