Python3 字符串 Python3 字符串


描述

Python splitlines() 按照行分隔,返回一個包含各行作為元素的列表,如果 num 指定則僅切片 num 個行.

語法

splitlines()方法語法:

str.splitlines( num=string.count('\n'))

參數(shù)

  • num -- 分割行的次數(shù)。

返回值

返回一個包含各行作為元素的列表。

實(shí)例

以下實(shí)例展示了splitlines()函數(shù)的使用方法:

#!/usr/bin/python3

str = "this is \nstring example....\nwow!!!"
print (str.splitlines( ))

以上實(shí)例輸出結(jié)果如下:

['this is ', 'string example....', 'wow!!!']

Python3 字符串 Python3 字符串