Skip to content

Document Operation in Python (Appending)

  • With the operation "a" (Appending) will allow the new data on end of the file
  • So we required to add \n (escape character) to insert a line break, without it the new data will stick with the old data (end of the file).

Usage

file-operation-append.py

py
file = open("./write-test.txt", mode="a", encoding="UTF-8")
file.write("\nHello, Python") # New line
file.close()

The file output:

write-test.txt

text
Hello, World
Hello, Python