擅长:python、mysql、java
<p>我假设您使用的是Python 3。<code>us.encode('utf-8') == "MyString"</code>返回<code>False</code>,因为<code>str.encode()</code>函数是<a href="http://docs.python.org/3/library/stdtypes.html#str.encode" rel="nofollow">returning a bytes object</a>:</p>
<pre><code>In [2]: us.encode('utf-8')
Out[2]: b'MyString'
</code></pre>
<p>在Python 3中,字符串是<a href="http://docs.python.org/3/library/stdtypes.html#text-sequence-type-str" rel="nofollow">already Unicode</a>,因此<code>u'MyString'</code>是多余的。</p>