Definition
The splitlines() method splits a string into a list. The splitting is done at line breaks.
Syntax
string.splitlines(keeplinebreaks)
Parameters
Parameter | Description |
---|---|
keeplinebreaks | Optional. Specifies if the line breaks should be included (True), or not (False). Default value is False |
Examples:
testStr = "Welcome to the Python tutorials. \nPython is a scripting language."
result = testStr.splitlines()
print(result)
# keeping the line breaks
testStr = "Welcome to the Python tutorials. \nPython is a scripting language."
result = testStr.splitlines(True)
print(result)