Skip to tool

Python str.splitlines() Online

Split into line list with optional line endings.

The output updates as you type. The tool processes input in your browser.

Worked example

Keep line endings to inspect the separators as well as the text. One final line ending does not create an additional empty entry.

Keep line endings
false
Sample input
line1
line2
line3
Sample output
[
  "line1",
  "line2",
  "line3"
]

Python example

print("line1\nline2\nline3".splitlines())
Expected native output
['line1', 'line2', 'line3']

Using this operation in Python

The interactive result uses JavaScript. Python str stores Unicode text. Encode to bytes when an API expects UTF-8 or another byte representation.

Python reference