.readline()

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()

Contributors

Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.

Learn Python on Codecademy

Contributors