换行符上的Python拆分字符串并保持换行符

时间:2017-08-16 10:49:22

标签: python split newline delimiter

有没有办法将包含换行符的字符串拆分为保留换行符的字符串列表,例如

"amount\nexceeds"

会产生

["amount\n", "exceeds"]

1 个答案:

答案 0 :(得分:8)

使用splitlines(),传递True:

"amount\nexceeds".splitlines(True)

给你:

["amount\n", "exceeds"]
相关问题