Check sibling questions

How is method write() different from writelines() in python?

 

Answer:

write( )

writelines( )

This method writes a string into a file.

This method writes a sequence of strings to the file.

Syntax:

str=”hello”

f.write(str)

Syntax:

strlist=[“hello”,”world”]

f.writelines(strlist)

  1. Computer Science - Class 12
  2. Chapter 2 - File Handling in Python

About the Author

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 and Computer Science at Teachoo