草稿 · 2022年5月1日 0

草稿:Python 多行字符串

方法一:
s1 = """Multi line strings can be put
        between triple quotes. It's not ideal
        when formatting your code though"""

print (s1)

结果:

Multi line strings can be put
         between triple quotes. It's not ideal
         when formatting your code though
方法二(推荐):

上面示例虽然可以实现字符串换行但是会多出很多空格。

s2 = ("You can also concatenate multiple\n" 
      "strings this way, but you'll have to\n"
      "explicitly put in the newlines")

print(s2)

结果:

You can also concatenate multiple
strings this way, but you'll have to
explicitly put in the newlines