Python - String Method - splitlines() Tutorial
The splitline() method will split the string at line breaks and return it in the form of a list.
Syntax-
String.splitlines(linebreak)
#linebreak - (Optional) It specifies if the line break should be included or not.
By default it is False
Example-
#\n ,\r, \u2028, \f are line break representation
str1 = "Sam\r is good\n in math,\n but he is \nbad in english"
print(str1.splitlines())
print(str1.splitlines(True))
#if there is no line break representation, it returns a list with a single item
str2 = "Sam is good in math, but he is bad in english"
print(str2.splitlines())
Output-
['Sam', ' is good', ' in math,', ' but he is ', 'bad in english']
['Sam\r', ' is good\n', ' in math,\n', ' but he is \n', 'bad in english']
['Sam is good in math, but he is bad in english']