Programming Examples

Write a Python program to open the file with a for appending, then add a list of texts to append to the file.


Write a Python program to open the file with “a” for appending, then add a list of texts to append to the file.

Solution

texts = [
    "This is the first appended line.\n",
    "This is the second appended line.\n",
    "This is the third appended line.\n"
]

with open("data.txt", "a") as file:
    file.writelines(texts)

print("Text appended to file successfully.")
▶ RUN

Output/ Explanation:

Latest Current Affairs 2026 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad