<p>要用Python打印字符串和数字,除了执行以下操作之外,还有其他方法吗:</p>
<pre><code>first = 10
second = 20
print "First number is %(first)d and second number is %(second)d" % {"first": first, "second":second}
</code></pre>
<p>是的。首选语法是支持<code>str.format</code>,而不是不推荐的<code>%</code>运算符。</p>
<pre><code>print "First number is {} and second number is {}".format(first, second)
</code></pre>