Split string using a newline delimiter with Python

后端 未结 5 1120
故里飘歌
故里飘歌 2020-11-27 18:01

I need to delimit the string which has new line in it. How would I achieve it? Please refer below code.

Input:

data = \"\"\"a,b,c
d,e,f
g,h,i
j,k,l\"         


        
5条回答
  •  野性不改
    2020-11-27 18:07

    str.splitlines method should give you exactly that.

    >>> data = """a,b,c
    ... d,e,f
    ... g,h,i
    ... j,k,l"""
    >>> data.splitlines()
    ['a,b,c', 'd,e,f', 'g,h,i', 'j,k,l']
    

提交回复
热议问题