Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

how to make a new line when appending a python external file

+8 votes
asked May 20, 2025 by Solomon Paourou (200 points)

2 Answers

0 votes
answered May 27, 2025 by A V S Manvith (220 points)

To add a new line when appending to an external file in Python, you simply include \n at the end (or beginning) of the string you're writing.

0 votes
answered May 29, 2025 by KIRUBA KARAN (140 points)
# Open the file in append mode ('a')
with open("example.txt", "a") as file:
    file.write("This is a new line.\n")
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...