Thuta Learning
IntermediateProgrammingbeginner

Python Read Files

Relax. We'll talk through this in plain words — no textbook voice.

To read a file, we use mode "r" with open().

read(): reads all the content

readline(): reads one line at a time

python
# First, create a file to read
with open("readme.txt", "w") as f:
    f.write("First line.\nSecond line.")

# Now, read the file
with open("readme.txt", "r") as f:
    content = f.read()
    print(content)
You should see
First line. Second line.
Python Read Files | Thuta Learning