Python Program to Append to a File – 2024

Hey guys, in this blog we will see a Python Program to Append to a File.

The content of the file my_file.txt is

Machine Learning Projects
Deep Learning Projects
Flask Projects

Open the file in append mode and write to it

with open("my_file.txt", "a") as f:
   f.write("CV Projects")

Output

Machine Learning Projects
Deep Learning Projects
Flask ProjectsCV Projects
  • Simply open the file in ‘a’ mode which stands for append mode.
  • Now write anything that you want to add to the file.
  • We have added ‘CV Projects’ and it got added directly after ‘Flask Projects’.
  • If you want to add items in the next line you do something like the following:
with open("my_file.txt", "a") as f:
   f.write("\nCV Projects")

Check out our other python programming examples

Abhishek Sharma
Abhishek Sharma

Started my Data Science journey in my 2nd year of college and since then continuously into it because of the magical powers of ML and continuously doing projects in almost every domain of AI like ML, DL, CV, NLP.

Articles: 520

Subscribe to our Newsletter

Subscribe to our newsletter and receive all latest projects...

Leave a Reply

Your email address will not be published. Required fields are marked *