长字符串

  要表示很长的字符串(跨越多行的字符串),可使用三个单引号或三个双引号。

>>> print('''This is a long story.            >>> print("""This is a long story.
... It continues here.                     ... It continues here.
... And it not over yet.                      ... And it not over yet.
... Hello World''')                           ... Hello World""")
This is a long story.                         This is a long story.
It continues here.                         It continues here.
And it not over yet.                         And it not over yet.
Hello World                               Hello World

  常规字符串也可跨越多行,只要在行尾加上反斜杠(‘\’),但其只输出一行。

>>> print('This is a long story.\
... It continues here.\
... And it not over yet.\
... Hello World')
This is a long story.It continues here.And it not over yet.Hello World

 

posted @ 2018-09-01 17:47  从python开始  阅读(252)  评论(0编辑  收藏  举报