What is the output of the following code? Explain.

 

Answer:

Output:

Hello, world!

How are you ?

Explanation:

  • Line 1 - opens file in write mode.
  • Line 2 & 3 - Writes the 2 lines to the opened file.
  • Line 4 -  close the text file.
  • Line 5 - reads the content in the text file.

 

Go Ad-free
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science, Social Science, Physics, Chemistry, Computer Science at Teachoo.