python3----splitlines

Python中的splitlines用来分割行。当传入的参数为True时,表示保留换行符 \n。通过下面的例子就很明白了:

 1 mulLine = """Hello!!!
 2  Wellcome to Python's world!
 3     There are a lot of interesting things!
 4         Enjoy yourself. Thank you!"""
 5 
 6 print(''.join(mulLine.splitlines()))
 7 print('------------')
 8 print(''.join(mulLine.splitlines(True)))
 9 
10 results:
11 
12 Hello!!! Wellcome to Python's world!    There are a lot of interesting things!        Enjoy yourself. Thank you!
13 ------------
14 Hello!!!
15  Wellcome to Python's world!
16     There are a lot of interesting things!
17         Enjoy yourself. Thank you!

 

posted @ 2018-01-11 19:45  jonm  阅读(409)  评论(0编辑  收藏  举报