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

PythonServer Side ProgrammingProgramming

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']


raja
Published on 14-Dec-2017 13:41:28
Advertisements