Python string splitlines split string by line separator

split string by line separator

splitlines method allows us to split a string by line breaks. It has the following syntax.

s.splitlines([keepends])

Splits string son line breaks, returning lines list. The result does not retain line break characters unless keepends is true.


paragraph = "This is a simple paragraph.\n\
It is made up of of multiple\n\# from  w  w w  .java2  s .c  om
lines of text."

print paragraph.splitlines(1)

The code above generates the following result.





















Home »
  Python »
    Data Types »




Data Types
String
String Format
Tuple
List
Set
Dictionary