Open In App

Numpy string operations | splitlines() function

Last Updated : 29 Aug, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

In this numpy.core.defchararray.splitlines() function, each element in arr, return a list of the lines in the element, breaking at line boundaries.

Syntax : numpy.core.defchararray.splitlines(arr, keepends = None)

Parameters :

arr : [array-like of str]  Given array-like of string.

keepends : [bool, optional] Line breaks are not included in the resulting list unless keepends is given and true.

Return : [ndarray] Return the Array of list objects.

Code #1 :  

Python3




# Python program explaining 
# numpy.char.splitlines() function 
  
# importing numpy as geek  
import numpy as geek 
  
gfg = geek.char.splitlines('GeeksforGeeks \n A computer science portal \n for geeks')
    
print (gfg)


Output :  

[‘GeeksforGeeks ‘, ‘ A computer science portal ‘, ‘ for geeks’]

Code #2 :  

Python3




# Python program explaining 
# numpy.char.splitlines() function 
  
# importing numpy as geek  
import numpy as geek 
  
gfg = geek.char.splitlines('This is \r a Python-Numpy \r article \r for geeks')
    
print (gfg)


Output : 

[‘This is ‘, ‘ a Python-Numpy ‘, ‘ article ‘, ‘ for geeks’]


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads