小册名称:Python合辑4-130个字符串操作示例
Python在换行符上拆分
s = 'line 1\nline 2\nline without newline'l = s.splitlines(True)print(l)
s = 'line 1\nline 2\nline without newline'
l = s.splitlines(True)
print(l)
Output:
['line 1\n', 'line 2\n', 'line without newline']