# open/create a file for writing example 1
file = open('sample_text.txt', 'w')
file.write("Hello, world!")
file.close()
# open/create a file for writing example 2 (using with statement)
with open('sample_text.txt', 'w') as file:
file.write("Hello, world!")
Each task below is interactive. Edit the code in the editor and click Run.
output.txt in write mode ('w')."Hulk Hogan" to the file.
output.txt in write mode ('w')."Hulk Hogan" to the file."Ultimate Warrior" to the file."Ted Dibiase" to the file."Randy Savage" to the file.