Find how many lines in string

后端 未结 4 1703
不思量自难忘°
不思量自难忘° 2020-12-17 08:55

I am creating a python movie player/maker, and I want to find the number of lines in a multiple line string. I was wondering if there was any built in function or function I

4条回答
  •  不思量自难忘°
    2020-12-17 09:25

    SPAM\nEGGS\nBEANS = Three lines, two line breaks

    So if counting lines, use + 1, or you'll make a fencepost error:

    x.count( "\n" ) + 1
    

提交回复
热议问题