Open and read
open("note.txt", encoding="utf-8") opens a file for reading. read() returns the whole text. close() lets go of the file.
The file in the list is already in the folder where your program runs.
A name, then the text
open takes a file name. The name is a string, and it is one segment: note.txt, not a path with a slash. The call returns a file object. That object is not the text. It is the handle you use to get the text.
read() with no argument returns every character that is in the file, as one string. For the file in this lesson, that string is Hello. It is not the name note.txt. The name is the string you passed to open.
The Input and output tutorial describes this pair of calls. Reading is the default mode, so you do not need a second mode argument. You do pass encoding="utf-8" so the file is decoded as text.

note.txt is already in the folder. open finds it by that name.openfinds the file and returns a handle.readreturns the text that is in the file.closelets go of the file so nothing else is holding it.
A worked example
Suppose note.txt contains Hello. These three lines read it and print it.
- Open
note.txtand keep the handle. - Read the whole text into a variable.
- Close the handle, then use the text.
text is "Hello". print shows that string. The function in the exercise should return the string instead of printing it. A return value is what the check compares. Printed text is only what you see.
Calling
f.write()without using thewithkeyword or callingf.close()might result in the arguments off.write()not being completely written to the disk, even if the program exits successfully.— Python tutorial, Reading and writing files
That warning is about writing. The same habit matters for reading: if you open a file, close it before the function ends. The next page shows with, which closes for you. This page asks you to call close yourself.
This program cannot be stepped through.
Return the string from read. Do not return the file name.
What does read() return?
Click the line that opens the file.
Put the lines in an order that reads note.txt and closes it.
text = handle.read()
print(text)
handle = open("note.txt", encoding="utf-8")handle.delete()
handle.close()
Exercise
Write a function named message. Open note.txt, read the text, close the file, and return the text. The file already contains Hello.
Write a function named message. Open note.txt, read the text, close the file, and return the text.