为什么这个Python脚本在多行字符串前面有一个\以及它的作用是什么?
在Python脚本中,我看到字符串前面有一个\:为什么这个Python脚本在多行字符串前面有一个\以及它的作用是什么?,python,string,multiline,Python,String,Multiline,在Python脚本中,我看到字符串前面有一个\: print """\ Content-Type: text/html\n <html><body> <p>The submited name was "%s"</p> </body></html> """ % name print”“”\ 内容类型:text/html\n 提交的名称为“%s” “”%name 如果我删除\它将断开。它做什么?它告诉Python忽略反斜杠后
print """\
Content-Type: text/html\n
<html><body>
<p>The submited name was "%s"</p>
</body></html>
""" % name
print”“”\
内容类型:text/html\n
提交的名称为“%s”
“”%name
如果我删除\它将断开。它做什么?它告诉Python忽略反斜杠后面的换行符。结果字符串以
内容类型开头:
,而不是以\n内容类型开头:
:
>>> '''\
This is the first line.
This is the second line.
'''
'This is the first line.\nThis is the second line.\n'
>>> '''
... This is the first line.
... This is the second line.
... '''
'\nThis is the first line.\nThis is the second line.\n'
注意这两个结果的不同之处;第一个在开头没有换行符,另一个在开头没有换行符