Splitlines() Method Of Str Class

Method Name:



Method Signature:



Method Overview:

  • splitlines() of Python str class, breaks a string into multiple strings based on a set of line separators and returns the result in a python list object


  • The line separator characters include


Line Separator



Line Feed


Carriage Return


Carriage Return and Line Feed

\v or \x0b

Line Tabulation, Vertical Tab

\f or \x0c

Form Feed


File Separator


Group Separator


Record Separator


Next Line


Line Separator


Paragraph Separator


  • Together with split() and splitlines()can be used to tokenize entire files of data which can be fed into relational data store or any other NoSQL data stores.


sampleText = """The Little Prince is

a classic tale of equal appeal

to children and grown ups."""

lines           = sampleText.splitlines()            




linesWithEnds   = sampleText.splitlines(keepends=True)




['The Little Prince is', 'a classic tale of equal appeal ', 'to children and grown ups.']

['The Little Prince is\n', 'a classic tale of equal appeal \n', 'to children and grown ups.']

Copyright 2024 © pythontic.com