擅长:python、mysql、java
<p>使用<code>format</code>方法,特别是当您关心Python 3和未来时。来自<a href="http://docs.python.org/release/3.1.5/library/stdtypes.html#old-string-formatting-operations" rel="nofollow noreferrer">the documentation</a>:</p>
<blockquote>
<p>The formatting operations described here are modelled on C's <code>printf()</code>
syntax. They only support formatting of certain builtin types. The
use of a binary operator means that care may be needed in order to
format tuples and dictionaries correctly. As the new
:ref:<code>string-formatting</code> syntax is more flexible and handles tuples and
dictionaries naturally, it is recommended for new code. However, there
are no current plans to deprecate <code>printf</code>-style formatting.</p>
</blockquote>