Append in File
Last Updated : 5th September 2025
Append a file means to append the content of a file to the end of the file.It Can not replace the content of the file.
1. write()
It appends the given content to the end of the file.
file = open("example.txt", "a")
file.write("Hello, World!")
- Append data between two lines
file = open("example.txt", "a")
file.write("Hello, World!\nThis is Python")
file.seek(13)
file.write("new content")
file.close()
- reading and appending a file
file = open("example.txt", "r+")
content = file.read() # Read the content of the file
file.write("new content") # Append new content to the end of the file
file.close()