擅长:python、mysql、java
<p>在Python>;=3.6中,您可以使用新的<a href="https://docs.python.org/3/reference/lexical_analysis.html#formatted-string-literals" rel="noreferrer">string literal</a>功能:</p>
<pre><code>with open('hst.txt', 'a') as fd:
fd.write(f'\n{name}')
</code></pre>
<p>请注意使用“<a href="https://docs.python.org/3/reference/compound_stmts.html#the-with-statement" rel="noreferrer">with statment</a>”将在fd超出范围时自动关闭文件</p>