Web Analytics

Python file.readlines() Method

File Method โ€ข Read List

The readlines() method returns a list containing each line in the file as a list item.

Use the hint parameter to limit the number of lines returned. If the total number of bytes returned exceeds the specified number, no more lines are returned.

Syntax

file.readlines(hint)

Parameters

Parameter Description
hint Optional. If the number of bytes returned exceed the hint number, no more lines will be returned. Default value is -1, which means all lines will be returned.

Return Value

A list of lines from the file.

Example

Using the readlines() method:

Output
Click Run to execute your code

Related Functions