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 String join()
Python List sort()
Python Program to Find ASCII Value of Character
Python String isnumeric()
Python Program to Check If a String Is a Number (Float)
Debug a JavaMail Program
Python vars()
Python List
Python Operator Overloading
Python Variables, Constants and Literals
Python Program to Add Two Matrices
Python input()
Python min()
Python String capitalize()
Python zip()
Python String expandtabs()
Python Program to Iterate Through Two Lists in Parallel
Python Errors and Built-in Exceptions
Python Objects and Classes
Python Program to Count the Number of Digits Present In a Number
Python Program to Trim Whitespace From a String
Python String zfill()
Python Directory and Files Management
Python Program to Convert Kilometers to Miles
Python String startswith()
Python Program to Find the Factorial of a Number
Python if...else Statement
Python Custom Exceptions
Python Program to Reverse a Number
Python File I/O Operation
Python Program to Print the Fibonacci sequence
Python Operators