Python3 splitlines() Method
Description
Python splitlines() splits at line boundaries (carriage return, carriage return plus newline, or newline) and returns a list with each line as an element. If keepends is False, line breaks are not included; if True, they are kept.
Syntax
Syntax of the splitlines() method:
str.splitlines([keepends])
Parameters
- keepends -- whether to remove line breaks (carriage return, carriage return plus newline, or newline) from the output. Defaults to False, which does not include line breaks; True keeps them.
Return Value
Returns a list with each line as an element.
Example
The following example shows how to use the splitlines() function:
>>> 'ab c\n\nde fg\rkl\r\n'.splitlines()
['ab c', '', 'de fg', 'kl']
>>> 'ab c\n\nde fg\rkl\r\n'.splitlines(True)
['ab c\n', '\n', 'de fg\r', 'kl\r\n']
>>>
Python3 Strings