String Methods
str.splitlines()
Split at recognized line boundaries, including LF, CR, CRLF (one boundary), vertical tab, form feed, file/group/record separators, NEL and Unicode line and paragraph separators. Empty input yields an empty list; a final line boundary does not introduce an extra field. Set keepends to retain each line ending. The original string is unchanged. The keepends argument is truth-tested; prefer explicit Boolean values.
Formal Syntax & Structure
python syntaxpython
text.splitlines(keepends=False)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| keepends | bool | Whether to preserve line-ending characters (truth-tested); defaults to False. |
Return Value
list[str]
Lines in original order.
Working Example
Example Snippetpython
text = "draft\r\nreview\u2028done\n"print(text.splitlines())print(text.splitlines(keepends=True))