← Python from Scratch
Lesson 73 of 78 · 5 XP
Warm-up: read a file warm-up
Theory and problem statement
Machine translation, not yet reviewed by a native speaker.
A file is opened with open(), and read() reads all of it into one string. with closes the file by itself when the block ends:
with open("notes.txt", encoding="utf-8") as f:
text = f.read()
print(text)
Task. The setup code has written the input to the file notes.txt. Read the file and print everything in it.
Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.