Computer Science
Answer
write() | writelines() |
---|---|
The write() method is used to write a single string to a file. | The writelines() method is used to write multiple strings to a file. |
The write() method takes a string as an argument. | The writelines() method takes an iterable object like lists, tuple, etc. containing strings as an argument. |
The write() method returns the number of characters written on to the file. | The writelines() method does not return the number of characters written in the file. |
Related Questions
Differentiate between text file and binary file.
Differentiate between readline() and readlines().
Write the use and syntax for the following methods:
- open()
- read()
- seek()
- dump()
Write the file mode that will be used for opening the following files. Also, write the Python statements to open the following files:
- a text file “example.txt” in both read and write mode.
- a binary file “bfile.dat” in write mode.
- a text file “try.txt” in append and read mode.
- a binary file “btry.dat” in read only mode.