with open() safely reads and writes a text file.
A text file stores characters. Use with open(...) so Python closes the file automatically; use "w" to write and "r" to read.
with open("notes.txt", "w", encoding="utf-8") as file:
file.write("Learning Python is fun!")
with open("notes.txt", "r", encoding="utf-8") as file:
content = file.read()
print(content)This playground creates notes.txt before reading it. The file lives only in the browser Python environment and is not a file on your computer.
Learning Python is fun!Change one value, then explain how the resulting data changes.
Keep this in mind: Follow each data operation in order before predicting the result.
with open("notes.txt", "w", encoding="utf-8") as file:
file.write("Learning Python is fun!")
with open("notes.txt", "r", encoding="utf-8") as file:
content = file.read()
print(content)
# Change the text, then run this complete example againRun the example, then change one value and observe the result.
