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 range()
Python sum()
Python Set symmetric_difference()
Python Program to Check the File Size
Python Program to Make a Flattened List from Nested List
Python Program to Count the Number of Digits Present In a Number
Python Set issubset()
Python del Statement
Python Program Read a File Line by Line Into a List
Python Decorators
Python compile()
Python Set pop()
Python list()
Python Program to Check If Two Strings are Anagram
Python Set symmetric_difference_update()
Python Modules
Python Program to Compute the Power of a Number
Python Program to Concatenate Two Lists
Python float()
Python frozenset()
Python getattr()
Python Program to Multiply Two Matrices
Python String capitalize()
Python Program to Convert Two Lists Into a Dictionary
Python String ljust()
Machine Learning Mastery with Python - Understand your data, create accurate models and work project...
Python format()
Applied Text Analysis with Python - Benjamin Benfort & Rebecca Bibro & Tony Ojeda
Deep Learning with Python - Francois Cholletf
Python File I/O Operation
Python id()
Python Program to Find the Sum of Natural Numbers