擅长:python、mysql、java
<p>python中有两种类型的字符串文字:</p>
<ul>
<li><p><code>"a string"</code>或<code>'a string'</code>表示单行字符串。</p></li>
<li><p><code>"""a string"""</code>或<code>'''a string'''</code>表示多行字符串。</p></li>
</ul>
<p>您所做的是(1)无法关闭字符串<code>,.2f</code>,并且(2)无意中打开了一个(三重引号)多行字符串文本:</p>
<pre><code>print('Gross pay: $', format(gross_pay, ',.2f), sep=''')
missing a close quote here ^ ^^^ Opened a string literal
</code></pre>
<p>解释器假定后面的所有内容都是该字符串文本的一部分。当它找不到右括号时(因为您从未关闭字符串文字),它就会抱怨。你知道吗</p>
<p>有两种解决方法:</p>
<ol>
<li>转义中间引号:<code>sep='\'')</code>。这将阻止python将其解释为多行文字。你知道吗</li>
<li>使用双引号:<code>sep="'")</code></li>
</ol>