Easy Tutorial
❮ Python Att List Min Python Att Dictionary Popitem ❯

Python3 splitlines() Method

Python3 Strings


Description

The Python splitlines() method splits the string at line breaks ('\r', '\r\n', '\n') and returns a list containing each line as an element. If the keepends parameter is False, line breaks are not included; if True, line breaks are retained.

Syntax

The syntax for the splitlines() method is:

str.splitlines([keepends])

Parameters

Return Value

Returns a list containing each line as an element.

Example

The following example demonstrates the use of 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

❮ Python Att List Min Python Att Dictionary Popitem ❯