<p>从python文档中获取文本:<a href="https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals" rel="nofollow noreferrer">https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals</a></p>
<blockquote>
<p>Bytes literals are always prefixed with 'b' or 'B'; they produce an
instance of the bytes type instead of the str type. They may only
contain ASCII characters; bytes with a numeric value of 128 or greater
must be expressed with escapes.</p>
<p>Both string and bytes literals may optionally be prefixed with a
letter 'r' or 'R'; such strings are called raw strings and treat
backslashes as literal characters. As a result, in string literals,
'\U' and '\u' escapes in raw strings are not treated specially. Given
that Python 2.x’s raw unicode literals behave differently than Python
3.x’s the 'ur' syntax is not supported.</p>
</blockquote>
<p>以及</p>
<blockquote>
<p>A string literal with 'f' or 'F' in its prefix is a formatted string
literal; see Formatted string literals. The 'f' may be combined with
'r', but not with 'b' or 'u', therefore raw formatted strings are
possible, but formatted bytes literals are not.</p>
</blockquote>
<p>所以:</p>
<ul>
<li><strong>r</strong>表示<strong>原始</strong></li>
<li><strong>b</strong>表示<strong>字节</strong></li>
<li><strong>u</strong>表示unicode<strong></li>
<li><strong>f</strong>表示<strong>格式</strong></li>
</ul>
<p>python2中已经提供了<strong>r</strong>和<strong>b</strong>,就像许多其他语言一样(它们有时非常方便)。在</p>
<p>由于python2中的字符串文本不是unicode,因此创建u字符串是为了提供国际化支持。在python3中,u字符串是默认字符串,因此“…”在语义上与u“…”相同。在</p>
<p>最后,从中可以看出,f-string是python2中唯一不支持的字符串。在</p>