例如
'a b\n\n\nc'.split()
给予
['a', 'b', 'c']
在我想要的时候
['a','b','','','c']
有什么想法吗?
请您参考如下方法:
使用str.splitlines .检查the docs你会看到它也在其他类似换行符的字符上 split 。如果您希望它仅在\n 上拆分,则使用str.split("\n")
>>> "a\n\n\nb".splitlines()
['a', '', '', 'b']
