How to split at NEWLINEs in Python?

PythonServer Side ProgrammingProgramming

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']
raja
Published on 12-Dec-2017 06:45:08
Advertisements