Menu
Coddy logo textTech

Read

Lesson 3 of 12 in Coddy's File Handling in Python course.

To read the content of a file use the function read():

f = open('coddy.txt')
s = f.read()

The above code, opens the file coddy.txt, reads the content of it and saves it in the variable s.

challenge icon

Challenge

Easy

Given the file named a.txt, read the content of the file and print it!

Try it yourself

All lessons in File Handling in Python