擅长:python、mysql、java
<p><strong>Python 3.6+(2017)</strong></p>
<p>在Python的最新版本中,可以使用<a href="https://docs.python.org/3/reference/lexical_analysis.html#f-strings" rel="noreferrer">f-strings</a>(另请参见<a href="https://www.python.org/dev/peps/pep-0498/" rel="noreferrer">PEP498</a>)</p>
<p>对于f字符串,应该使用双精度<code>{{</code>或<code>}}</code></p>
<pre><code>n = 42
print(f" {{Hello}} {n} ")
</code></pre>
<p>产生所需的结果</p>
<pre><code> {Hello} 42
</code></pre>
<p>如果需要解析括号中的表达式而不是使用文本,则需要三组括号:</p>
<pre><code>hello = "HELLO"
print(f"{{{hello.lower()}}}")
</code></pre>
<p>产生</p>
<pre><code>{hello}
</code></pre>