Home >>Python String Methods >Python String splitlines() Method

Python String splitlines() Method

Python String splitlines() Method

Python string splitlines() method is used to split the given input string into a list. The splitting is done at line breaks.

Syntax:
string.splitlines(keeplinebreaks)

Parameter Values

Parameter Description
keeplinebreaks This is an optional parameter. It defines if the line breaks should be included or not.
Here is an example of Python splitlines() method:

txt = "Hello, I am Jerry\nWelcome to PHPTPOINT"
x = txt.splitlines()
print(x)

Output:
['Hello, I am Jerry', 'Welcome to PHPTPOINT']
Example 2:

txt = "Hello, I am Jerry\nWelcome to PHPTPOINT"
x = txt.splitlines(True)
print(x)

Output:
['Hello, I am Jerry\n', 'Welcome to PHPTPOINT']s

No Sidebar ads