Q. The file "New.txt" contains the following:-


Better than Heaven or Arcadia

I love thee, O my India !

And thy love I shall give

To every brother nation that lives.


Considering the given file, what output will be produced by the following code ?


obj1 = open("New.txt","r")

s1 = obj1.readline()

s2 = obj1.readline()

s3 = obj1.readline()

s4 = obj1.read(15)

print (s4)

obj1.close()


Answer :-


The output produced by the above code is:

To every brothe
>>>

Explanation :-

Due to "s1 = obj1.readline()" statement, the pointer goes to the second line, and again due to "s2 = obj1.readline()" and "s2 = obj1.readline()" the pointer goes to 4th line then "s4 = obj1.read(15)" statement read 15 character of that txt file. So our output will be :- To every brothe.

4 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post