Computer >> Computer tutorials >  >> Programming >> Python

How do I split a multi-line string into multiple lines?


We can use the method splitlines() in string class to achieve this. 

example

>>> """some
multi line
string""".splitlines()
['some', 'multi line', 'string']

We can also specify the delimiter '\n' in the split() method as follows −

>>> """some
multi line
string""".split('\n')
['some', 'multi line', 'string']