English

Explain the use of output function writelines() with an example.

Advertisements
Advertisements

Question

Explain the use of output function writelines() with an example.

Code Writing
Explain
Advertisements

Solution

writelines(): Writes a sequence of strings. Newline characters must be supplied by the programmer.

lines = ["First line\n", "Second line\n"]
with open("data.txt", "w") as file:
    file.writelines(lines)
shaalaa.com
  Is there an error in this question or solution?
Chapter 7: Data File Handling - EXERCISE [Page 145]

APPEARS IN

CBSE Computer Science with Python [English] Class 12
Chapter 7 Data File Handling
EXERCISE | Q 9. b. | Page 145
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×