willsonlincake 发表于 2022-4-2 00:02:47

Python按照行分隔

str1 = 'ab c\n\nde fg\rkl\r\n'
print str1.splitlines();
这个是不保留换行符符号的,输出结果:
['ab c', '', 'de fg', 'kl']

str2 = 'ab c\n\nde fg\rkl\r\n'
print str2.splitlines(True)
这个是保留换行符号的,输出结果为:
['ab c\n', '\n', 'de fg\r', 'kl\r\n']

蓝莓糖 发表于 2022-4-2 08:08:02

牛!

自然 发表于 2022-4-2 16:47:11

蓝莓糖 发表于 2022-4-2 08:08
牛!

页: [1]
查看完整版本: Python按照行分隔