擅长:python、mysql、java
<p>注意<code>print</code>是Python2和Python3之间的区别之一。在Python3中,<code>print</code>是一个函数,<code>print(name, 'lives in', location)</code>将打印<code>jen lives in dhaka</code></p>
<p>但是在Python2中,<code>print</code>是一条指令,因此<code>print(name, 'lives in', location)</code>打印元组(因为逗号)<code>(name, 'lives in', location)</code>以<code>('jen', 'lives in', 'Dhaka')</code>结尾的元组</p>
<p>要获得预期的输出,可以省略括号:</p>
<pre><code>print name, 'lives in', location
</code></pre>
<p>或者使用join连接字符串</p>
<pre><code>print(''.join(name, 'lives in', location))
</code></pre>
<p>由于外圆括号的内容只是一个字符串(没有逗号),因此在Python2中它们变得无害</p>