How do I loop through a string?

I have a string which contains multiple lines, for example:

str ="""hello world
bye world
what's up world
"""

Initially, I had a file which contained the same text as in the string above through which I could iterate line by line using:

with open(sometext.seq.raw) as file:
      for line in file:

How do I do the same with the str?

Try splitting the string up based on an end of line character. That will give you each line.

1 Like

with the splitlines() function?

That or the regular split function.

1 Like