擅长:python、mysql、java
<p>您需要将<code>{{</code>和<code>}}</code>加倍:</p>
<pre><code>>>> x = " {{ Hello }} {0} "
>>> print(x.format(42))
' { Hello } 42 '
</code></pre>
<p>以下是<a href="https://docs.python.org/library/string.html#formatstrings" rel="noreferrer">Python documentation for format string syntax</a>的相关部分:</p>
<blockquote>
<p>Format strings contain “replacement fields” surrounded by curly braces <code>{}</code>. Anything that is not contained in braces is considered literal text, which is copied unchanged to the output. If you need to include a brace character in the literal text, it can be escaped by doubling: <code>{{</code> and <code>}}</code>.</p>
</blockquote>