<p>您使用的是<code>print</code><em>语句</em>,而不是函数,有几种方法:</p>
<p>这将使用三重引号字符串来保留换行符:</p>
<pre><code>def printit():
print """NUCLEAR CORE UNSTABLE!!!
Quarantine is in effect.
Surrounding hamlets will be evacuated.
Anti-radiationsuits and iodine pills are mandatory.
"""
</code></pre>
<p>只需运行3次:</p>
<pre><code>for i in range(3):
printit()
</code></pre>
<p>它使用多个<code>print</code>语句:</p>
<pre><code>def printit():
print "NUCLEAR CORE UNSTABLE!!!"
print "Quarantine is in effect."
print "Surrounding hamlets will be evacuated."
print "Anti-radiationsuits and iodine pills are mandatory.\n"
</code></pre>
<p>这只使用一行内嵌的换行符:</p>
<pre><code>def printit():
print "NUCLEAR CORE UNSTABLE!!!\nQuarantine is in effect.\nSurrounding hamlets will be evacuated.\nAnti-radiationsuits and iodine pills are mandatory.\n"
</code></pre>
<p>但是,您提到<code>print</code><em>函数</em>并抱怨逗号分隔符没有起到任何作用,因此:</p>
<pre><code>from __future__ import print_function
def printit():
print ("NUCLEAR CORE UNSTABLE!!!",
"Quarantine is in effect.",
"Surrounding hamlets will be evacuated.",
"Anti-radiationsuits and iodine pills are mandatory.\n",
sep="\n")
</code></pre>
<p>我个人比较喜欢这个。您可以将所有代码放在一行中,但这会使代码难以读取和维护</p>