text_file = open("File.txt", "w") #Creating a "txt" file. This will overwrite your old text values. #If you want to overwrite: text_file.write("Hello!") #Deleted all the old texts in the "txt" file and just typed "Hello!" in it. #To make it not overwrite: text_file = open("File.txt", "r") text = text_file.read() #Reading the contents of the "txt" file new_text = "Hello!" #We are going to write "Hello" in the "txt" file with open("File.txt", "w") as text_file: #Opening it as a "w" because we got the values from the txt file, and ready to overwrite with it text_file.write(text, new_text) #Writing the texts into the "txt" file text_file.close #Closing the "txt" file