In this example, you will learn to append to a file.
To understand this example, you should have the knowledge of the following Python programming topics:
Open file in append mode and write to it
The content of the file my_file.txt is
honda 1948 mercedes 1926 ford 1903
The source code to write to a file in append mode is:
with open("my_file.txt", "a") as f:
f.write("new text")
The content of the file after appending a text to it is:
honda 1948 mercedes 1926 ford 1903new text
Open the file in append 'a' mode, and write to it using write() method. Inside write() method, a string "new text" is passed. This text is seen on the file as shown above.
If you want to learn more about different types of file opening modes, please refer to Python file I/O.
Related posts:
Python zip()
Python String capitalize()
Python Program to Check Prime Number
Python Program to Calculate the Area of a Triangle
Python Program to Count the Number of Each Vowel
Python range()
Python Program to Differentiate Between type() and isinstance()
Python Program to Find Armstrong Number in an Interval
Python Program to Find Hash of File
Python Data Analytics with Pandas, NumPy and Matplotlib - Fabio Nelli
Python Dictionary keys()
Python oct()
Python locals()
Python Program to Find the Square Root
Python Program to Get the File Name From the File Path
Python File I/O Operation
Python map()
Python Program to Create a Long Multiline String
Python list()
Python Anonymous / Lambda Function
Python Program to Convert Decimal to Binary Using Recursion
Node.js vs Python for Backend Development
Python Set add()
Python strftime()
Python issubclass()
Python Program to Illustrate Different Set Operations
Python String isnumeric()
Python Program to Copy a File
Python Program to Convert Decimal to Binary, Octal and Hexadecimal
Python Set issubset()
Python List Comprehension
Deep Learning with Applications Using Python - Navin Kumar Manaswi