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.")
Output

Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Best Website and Software Company in Allahabad