splitlines(): splitting a string at line breaks in Python

Use the splitlines() method to split a string at line breaks.

The return of the method is a list of the lines.

my_string = 'world \n cup'

print(my_string.splitlines())
#output: ['world ', ' cup']

If you want to keep the line break, the splitlines() accepts a parameter that can be set to True, the default is False.

my_string = 'world \n cup'

print(my_string.splitlines(True))
#output: ['world \n', ' cup']

I also recommend you to check the more generic split() method in this post How to Split a String in Python.