Python 3 - String splitlines() Method


Advertisements

Description

The splitlines() method returns a list with all the lines in string, optionally including the line breaks (if num is supplied and is true).

Syntax

Following is the syntax for splitlines() method −

str.splitlines( num = string.count('\n'))

Parameters

num − This is any number, if present then it would be assumed that line breaks need to be included in the lines.

Return Value

This method returns true if found matching string otherwise false.

Example

The following example shows the usage of splitlines() method.

#!/usr/bin/python3

str = "this is \nstring example....\nwow!!!"
print (str.splitlines( ))

Result

When we run above program, it produces the following result −

['this is ', 'string example....', 'wow!!!']
python_strings.htm
Advertisements