Split string using a newline delimiter with Python

后端 未结 5 1125
故里飘歌
故里飘歌 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:29

    There is a method specifically for this purpose:

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

提交回复
热议问题