Chapters
Python114 chapters

ReferenceString methods

str.splitlines()

Breaks text into lines, without the trailing empty piece split("\n") leaves.

Signature

text.splitlines(keepends=False)

Parameters

NameMeans
keependskeep the line breaks when True

Returns

A list of strings.

Example

Python
text = "Ada\nGrace\n"
print(text.splitlines())
print(text.split("\n"))

Output

['Ada', 'Grace']
['Ada', 'Grace', '']

See also