Syntax :
string.splitlines((keepends>)
Parameters :
keepends (optional) : When set to True line breaks are included in the resulting list.
This can be a number , specifying the position of line break or, can be any Unicode characters , like “”, “”, “”, etc as boundaries for strings.
Returned value:
Returns a list of the lines in the string, breaking at line boundaries.
The code below shows an illustration of the splitline () method.
Code # 1
|
Output:
[’Welcome everyone to’,’ the world of Geeks’, ’GeeksforGeeks’] [’ Welcome everyone to’, ’the world of Geeks’,’ GeeksforGeeks’] [’Welcome everyone to’, ’the world of Geeks ’,’ GeeksforGeeks’]
Code # 2
|
Output:
[’Cat’,’ Bat’, ’ Sat’, ’Mat’,’ Xat’, ’Eat’] [’ India’, ’Japan’,’ USA’, ’UK’,’ Canada’]
Practical Application:
In this code we will understand how to use the splitlines () concept to calculate the length of each word in a line.
|
Output:
[’Welcome’,’ to’, ’GeeksforGeeks’] [7, 2, 13]