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
Copy Code
string.splitlines(keep_linebreaks = False)
Parameters
Parameter | Description |
---|---|
keep_linebreaks |
Optional. If true then do not remove linebreaks from the end of the strings returned. The default is False |
Example
Python
Copy Code
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']