First page Back Continue Last page Overview Graphics

Disassemble String in Lines

str.splitlines([keepends])

Returns a list of the lines in the string, breaking at line boundaries. Line breaks are not included in the resulting list unless keepends is given and true.

>>> rhyme = "An apple a day\nSends the doctor away\n"

>>> rhyme.splitlines()

['An apple a day', 'Sends the doctor away']

>>> rhyme.splitlines(True)

['An apple a day\n', 'Sends the doctor away\n']

By comparison:

>>> rhyme.split("\n")

['An apple a day', 'Sends the doctor away', '']

>>> rhyme.split()

['An', 'apple', 'a', 'day', 'Sends', 'the', 'doctor', 'away']