What is the numpy.char.splitlines() function in Python?
Overview
The char.splitlines() function in Python is used to return a list of lines in the element of an input array of strings or Unicode, breaking at line boundaries.
Syntax
char.splitlines(a, keepends=None)
Parameter
The char.splitlines() function takes the following parameter values:
a: The input array of strings or Unicode.keepends: Takes a boolean value whether line breaks are to be included in the resulting list or not.
Example
Let’s look at the code below:
import numpy as np# implementing the char.splitlines() function using keepends as Trueprint(np.char.splitlines("I love \nnumpy \nso very \nmuch", keepends= True))# using keepends as Falseprint(np.char.splitlines("I love \nnumpy \nso very \nmuch", keepends= False))
Explanation
In the code above:
- Line 1: We import the
numpymodule. - Line 4: We implement the
char.splitlines()function on an array of strings using thekeepeendsvalue asTrue. We obtain and print our results to the console. - Line 7: We implement the
char.splitlines()function on an array of strings using thekeepeendsvalue asFalse. We obtain and print our results to the console.