Python 3 – String splitlines() 方法

Python 3 – String splitlines() 方法

Description

The splitlines() 方法返回一个包含字符串中所有行的列表,可选地包括行结束符(如果指定 num 并且为真)。

Syntax

以下是 splitlines() 方法的语法 −

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

Parameters

num − 任何数字,如果存在,则假定需要包含行结束符。

Return Value

如果找到匹配的字符串,则该方法返回 true,否则返回 false。

Example

以下示例演示了 splitlines() 方法的用法。

#!/usr/bin/python3
str = "this is \nstring example....\nwow!!!"
print (str.splitlines( ))

Result

当我们运行上面的程序时,它会生成以下结果−

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

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程