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

How to split at NEWLINEs in Python?


We can use the method splitlines() in string class to achieve this. For 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']