擅长:python、mysql、java
<p>在Python2.7中,逗号表示字符串将打印在同一行上</p>
<p>例如:</p>
<pre><code>for i in xrange(10):
print i,
</code></pre>
<p>这将打印</p>
<pre><code>1 2 3 4 5 6 7 8 9
</code></pre>
<p>要在Python3中执行此操作,请执行以下操作:</p>
<pre><code> for i in xrange(10):
print(i,end=" ")
</code></pre>
<p>你可能会发现这个答案很有用</p>
<p><a href="https://stackoverflow.com/questions/18458024/cant-figure-out-how-to-print-horizontally-in-python/18458089#18458089">Printing horizontally in python</a></p>
<p>----编辑---</p>
<p>文档<a href="http://docs.python.org/2/reference/simple_stmts.html#the-print-statement" rel="noreferrer">http://docs.python.org/2/reference/simple_stmts.html#the-print-statement</a>说</p>
<blockquote>
<p>A '\n' character is written at the end, unless the print statement ends with a comma.</p>
</blockquote>