Write a statement to write the string “Welcome! Please have a seat” in a file wel.txt, that has not yet been opened.

 

Answer:

f1 = open ("wel.txt", 'w') 

f1.write ("Welcome! Please have a seat") 

Here,

  • f1 is the file object.
  • open( ) method opens the file for writing to it.
  • “wel.text” is the file name.
  • ‘w’ is the access mode ie., the file is opened to write to it. 
  • write( ) method writes the specified string to the file.
Ask a doubt
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.