0

I can append new texts but cant get newline

I tried adding newline to the hello world but instead of new line it just simply add my first line and hello world to the previous line.

myfile=open("test.txt","a")
myfile.write("\nhello world")
myfile.close()

my first line
hello world
  • That's how escape characters work. If you want to add the '\n' as a normal string to file, you may prefix the escape character with a '\'. Like `"\\nhello world"`. – Jerome Escalante Dec 28 '18 at 03:40
  • Possible duplicate of [How would I specify a new line in Python?](https://stackoverflow.com/questions/11497376/how-would-i-specify-a-new-line-in-python) – Akber Iqbal Dec 28 '18 at 04:13

0 Answers0