擅长:python、mysql、java
<p>在Python 3上,<a href="https://docs.python.org/library/functions.html#print" rel="noreferrer">^{<cd1>}</a>可以采用可选的<code>flush</code>参数</p>
<pre><code>print("Hello world!", flush=True)
</code></pre>
<p>在Python 2上,您必须执行以下操作</p>
<pre><code>import sys
sys.stdout.flush()
</code></pre>
<p>在调用<code>print</code>之后。默认情况下,<a href="https://docs.python.org/2/reference/simple_stmts.html#the-print-statement" rel="noreferrer">^{<cd1>}</a>打印到<a href="https://docs.python.org/2/library/sys.html#sys.stdout" rel="noreferrer">^{<cd5>}</a>(有关<a href="https://docs.python.org/2/library/stdtypes.html#file-objects" rel="noreferrer">file objects</a>的详细信息,请参阅文档)。</p>