Python String splitlines() Method

Splits a line by carriage returns and/or line feed characaters. The return is an array of strings representing separate lines.

Syntax

Python
string.splitlines(keep_linebreaks = False)

Parameters

ParameterDescription
keep_linebreaks Optional. If true then do not remove linebreaks from the end of the strings returned. The default is False

Example

Python
print('Hello\rWorld'.splitlines())    # carriage return
print('Hello\r\nWorld'.splitlines())  # carriage return and new line
print('Hello\nWorld'.splitlines())    # new line

Output

['Hello', 'World']
['Hello', 'World']
['Hello', 'World']