Python 去除字符串中的空行

Python 去除字符串中的空行

mystr = 'adfa\n\n\ndsfsf'
print("".join([s for s in mystr.splitlines(True) if s.strip()]))

 

posted @ 2019-06-13 16:57  ibingshan  阅读(5839)  评论(0编辑  收藏  举报