.readline()

Anonymous contributors
Anonymous contributors
Published May 10, 2021Updated Apr 12, 2022
Contribute to Docs

The .readline() returns the first line of content from an open file.

Syntax

file.readline()

Example

Use .readline() to read the first line of content from the gullivers_travels.txt file:

f = open("gullivers_travels.txt", "r", encoding='utf8')
f.readline()

All contributors

Looking to contribute?

Learn Python on Codecademy