
Andrew K. answered 02/18/23
Master's Degree with 5+ years of Python Experience
#Open the file
#'w' ensures the file will be overwritten
f = open('example1.txt', 'w')
#Write a line to the file
#The '\n' creates a new line (so the next write doesn't end up on the same line)
f.write('Hello' + '\n')
#Write another line
f.write('World')
#Close the file
f.close()