Here is how to append text in a text file in Python.
with open('my_file.txt', 'a') as file:
file.write('Hello World!')
Output
Explanation
In this example, the with statement is used to open the file my_file.txt in append mode (indicated by the 'a' flag). The write() method is then used to append the string 'Hello World!' to the file.
Note: This example assumes that the file my_file.txt already exists. If the file does not exist, it will be created when the write() method is called.