Python Programming - Reading and Writing Files - Discussion

Discussion Forum : Reading and Writing Files - General Questions (Q.No. 88)
88.
How can you write a list of strings to a text file named "output.txt" in Python, with each string on a new line?
with open("output.txt", "w") as file:
    strings = ["Hello", "World", "Python"]
    file.write("\n".join(strings))
write_lines("output.txt", ["Hello", "World", "Python"])
text.write("output.txt", ["Hello", "World", "Python"])
with open("output.txt", "w") as file:
    file.writelines(["Hello", "World", "Python"])
Answer: Option
Explanation:
Using "\n".join(strings) to join the strings with newline characters.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.