String Methods
splitlines()
Split text at line boundaries.
str.splitlines(keepends=False)
str.splitlines() returns a list of lines in the string, breaking at line boundaries (\n, \r\n, \r).
Parameters
| Name | Description |
|---|---|
| keepends | If True, keep each line ending in the returned pieces. |
Returns
A list of lines.
Try it
Run it and change it
text = "first\nsecond" print(text.splitlines())
Worth knowing
- keepends option: Passing
keepends=Truepreserves the trailing newline characters in each item of the returned list.