I have a multi-line string that I want to do an operation on each line, like so:
inputString = """Line 1
Line 2
Line 3"""
I want to iterate on each line:
for line in inputString:
doStuff()
pythonsplitstring
I have a multi-line string that I want to do an operation on each line, like so:
inputString = """Line 1
Line 2
Line 3"""
I want to iterate on each line:
for line in inputString:
doStuff()
Best Answer
Will give you a list with each item, the
splitlines()
method is designed to split each line into a list element.