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

splitlinesmulLine = """Hello!!!
splitlines Wellcome to Python's world!
splitlines    There are a lot of interesting things!
splitlines        Enjoy yourself. Thank you!
"""
splitlines
splitlines
print ''.join(mulLine.splitlines())
splitlines
print '------------'
splitlines
print ''.join(mulLine.splitlines(True))


输出结果:
Hello!!! Wellcome to Python's world!    There are a lot of interesting things!        Enjoy yourself. Thank you!
------------
Hello!!!
 Wellcome to Python's world!
    There are a lot of interesting things!
        Enjoy yourself. Thank you!

作者:CoderZhCoderZh的技术博客 - 博客园
出处:http://coderzh.cnblogs.com/

 

相关文章:

  • 2021-06-13
  • 2022-12-23
  • 2021-05-24
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-09
  • 2022-12-23
  • 2021-09-09
  • 2021-08-15
相关资源
相似解决方案