x = 5.0 # Writing a new file file = open('filename.txt','w') file.write('The value of x is '+str(x)+'\n') #' \n' = newline file.close() # Appending to a file # Writing a new file file = open('filename.txt','a') file.write('The value of x is '+str(x)) file.close()