Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python3 splitlines() Method

Python3 splitlines() Method

Python3 Strings Python3 Strings


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

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 Python3 Strings