splitlines()方法返回字符串的所有行列表,可选包括换行符(如果num提供那么为true)
语法
下面是 splitlines()方法的语法 -
str.splitlines( num=string.count('\n'))
参数
-
num -- 这可以是任何数目,如果存在则它将假设换行符需要包括在行中。
返回值
如果找到匹配的字符串该方法返回true,否则为false。
示例
下面的例子显示 splitlines()方法的使用。
#!/usr/bin/python3 str = "this is \nstring example....\nwow!!!" print (str.splitlines( ))
当我们运行上面的程序,会产生以下结果 -
['this is ', 'string example....', 'wow!!!']
上一篇:
Python3数字
下一篇:
Python3字符串