how to write to a file in python without deleting all content

file = open("FILE_NAME.txt", "w+") # opens the file in both read and write mode

Here is what the above code is Doing:
1. The open() function opens the file in the mode specified as the second argument.
2. The first argument is the name of the file.
3. The mode can be ‘r’ when the file will only be read, ‘w’ for only writing (an existing file with the same name will be erased), and ‘a’ opens the file for appending; any data written to the file is automatically added to the end. ‘r+’ opens the file for both reading and writing.
4. The plus sign (+) after the mode argument specifies that you want to open a disk file for updating (reading and writing).
5. The w+ mode clears the contents of the file; any data that was in the file before the opened is erased.
6. The a+ mode retains the existing data in the file; any data written is appended to the end of the file.
7. The r+ mode retains the existing data in the file; any data written will overwrite the existing data in the file.