擅长:python、mysql、java
<p>不,你不能。Python 3中的<code>print</code>语句已不存在;编译器不再支持它。</p>
<p>您可以让<code>print()</code>像Python 2</em>中的函数一样工作;将它放在使用<code>print</code>的每个模块的顶部:</p>
<pre><code>from __future__ import print_function
</code></pre>
<p>这将删除对Python 2中的<code>print</code>语句的支持,就像在Python 3中一样,您可以使用<a href="https://docs.python.org/2/library/functions.html#print" rel="noreferrer">^{<cd2>} function that ships with Python 2</a>。</p>
<p><code>six</code>只能帮助桥接同时使用Python 2和3编写的代码;这包括将<code>print</code>语句替换为<code>print()</code>函数<em>first</em>。</p>
<p>您可能想阅读<a href="https://docs.python.org/3/howto/pyporting.html" rel="noreferrer"><em>Porting Python 2 Code to Python 3</em> howto</a>;它还将告诉您更多类似<code>from __future__</code>的导入,以及介绍诸如<a href="http://python-modernize.readthedocs.org/en/latest/" rel="noreferrer">Modernize</a>和<a href="http://python-future.org/automatic_conversion.html" rel="noreferrer">Futurize</a>之类的工具,这些工具可以帮助自动修复Python 2代码,使其在python2和3上都能工作。</p>