Python splitlines()方法
Python 教程
· 2019-02-02 17:57:54
描述
Python splitlines() 按照行('\r', '\r\n', \n')分隔,返回一个包含各行作为元素的列表,如果参数 keepends 为 False,不包含换行符,如果为 True,则保留换行符。
语法
splitlines()方法语法:
str.splitlines([keepends])
参数
- keepends -- 在输出结果里是否保留换行符('\r', '\r\n', \n'),默认为 False,不包含换行符,如果为 True,则保留换行符。
返回值
返回一个包含各行作为元素的列表。
实例
以下实例展示了splitlines()函数的使用方法:
实例(Python 2.0+)
#!/usr/bin/python
str1 = 'ab c\n\nde fg\rkl\r\n'
print str1.splitlines();
str2 = 'ab c\n\nde fg\rkl\r\n'
print str2.splitlines(True)
以上实例输出结果如下:
['ab c', '', 'de fg', 'kl'] ['ab c\n', '\n', 'de fg\r', 'kl\r\n']
点击查看所有 Python 教程 文章: https://www.codercto.com/courses/l/8.html
Complexity and Approximation
G. Ausiello、P. Crescenzi、V. Kann、Marchetti-sp、Giorgio Gambosi、Alberto M. Spaccamela / Springer / 2003-02 / USD 74.95
This book is an up-to-date documentation of the state of the art in combinatorial optimization, presenting approximate solutions of virtually all relevant classes of NP-hard optimization problems. The......一起来看看 《Complexity and Approximation》 这本书的介绍吧!