splitline() method is used to split the lines at line boundaries. The function returns a list of lines in the string, including the line break(optional).
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 “\n”, “\r”, “\r\n”, etc as boundaries for strings.
Return Value :
Returns a list of the lines in the string, breaking at line boundaries.
The below code shows the illustration of splitline() method.
['Welcome everyone to', 'the world of Geeks', 'GeeksforGeeks'] ['Welcome everyone to', 'the world of Geeks', 'GeeksforGeeks'] ['Welcome everyone to\r', 'the world of Geeks\n', 'GeeksforGeeks']
['Cat', 'Bat', 'Sat', 'Mat', 'Xat', 'Eat'] ['India', 'Japan', 'USA', 'UK', 'Canada']
In this code, we will understand how to use the concept of splitlines() to calculate the length of each word in a string.
['Welcome', 'to', 'GeeksforGeeks'] [7, 2, 13]
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.