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 isnumeric()
Statistical Methods for Machine Learning - Disconver how to Transform data into Knowledge with Pytho...
Python String isspace()
Python sleep()
Python Program to Create a Long Multiline String
Python Program to Generate a Random Number
Python format()
Python slice()
Python Dictionary popitem()
Python List
Python Program to Find the Square Root
Python String rjust()
Python Program to Find All File with .txt Extension Present Inside a Directory
Python Program to Add Two Matrices
Python String rpartition()
Node.js vs Python for Backend Development
Python Program to Compute all the Permutation of the String
Python String endswith()
Python String rindex()
Python Program to Print Output Without a Newline
Python Dictionary items()
Python Dictionary clear()
Python String rfind()
Python Program to Get a Substring of a String
Python hasattr()
Python Program to Measure the Elapsed Time in Python
Python strptime()
Python bytes()
Python range()
Python Exception Handling Using try, except and finally statement
Python Program to Shuffle Deck of Cards
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey