Thursday, 23 September 2021

Python: splitlines: get list of lines in the string

‘splitlines’ method return a list of the lines in the string, breaking at line boundaries.

 

Signature

splits = str.splitlines()

 

splitlines_demo_1.py

str = """Hello world
How are you
I am fine, what about you
I am good, thank you...."""

splits = str.splitlines()

for temp_str in splits:
    print(temp_str)

Output

Hello world
How are you
I am fine, what about you
I am good, thank you....



Previous                                                    Next                                                    Home

No comments:

Post a Comment