Chapters
Python114 chapters

ReferenceFile methods

file.readlines()

Reads every line into a list, newlines included.

Signature

f.readlines()

Returns

A list of strings.

Example

Python
with open("names.txt", "w", encoding="utf-8") as f:
    f.write("Ada\nGrace\n")

with open("names.txt", encoding="utf-8") as f:
    print(f.readlines())

Output

['Ada\n', 'Grace\n']

See also