len(unicode string)
<pre><code>&gt;&gt;&gt; c='ä¸­æ'
&gt;&gt;&gt; c
'\xe4\xb8\xad\xe6\x96\x87'
&gt;&gt;&gt; len(c)
6
&gt;&gt;&gt; cu=u'ä¸­æ'
&gt;&gt;&gt; cu
u'\u4e2d\u6587'
&gt;&gt;&gt; len(cu)
2
&gt;&gt;&gt; s='í¡í½¢'
&gt;&gt;&gt; s
'\xf0\xa4\xad\xa2'
&gt;&gt;&gt; len(s)
4
&gt;&gt;&gt; su=u'í¡í½¢'
&gt;&gt;&gt; su
u'\U00024b62'
&gt;&gt;&gt; len(su)
2
&gt;&gt;&gt; import sys
&gt;&gt;&gt; sys.getdefaultencoding()
'ascii'
&gt;&gt;&gt; sys.stdout.encoding
'UTF-8'
</code></pre>

<p>First, I want to make some concepts clear myself.
I've learned that unicode string like <code>cu=u'ä¸­æ'</code> ,actually is encoded in UTF-16 by python shell default. Right? <strong>So, when we saw <code>'\u*'</code> , that actually <code>UTF-16 encoding</code>? And <code>'\u4e2d\u6587'</code> is an unicode string or byte string?</strong> But <code>cu</code> has to be stored in the memory, so </p>

<pre><code>0100 1110 0010 1101 0110 0101 1000 0111
</code></pre>

<p>(convert \u4e2d\u6587 to binary) is the form that <code>cu</code> preserved if that a byte string? <strong>Am I right?</strong> </p>

<p>But it can't be byte string. Otherwise len(cu) can't be 2, it should be 4!!
So it has to be unicode string. <strong>BUT!!!</strong> I've also <a href="http://stackoverflow.com/questions/2596714/why-does-python-print-unicode-characters-when-the-default-encoding-is-ascii/21968640#21968640">learned</a> that </p>

<blockquote>
  <p>python attempts to implicitly encode the Unicode string with whatever
  scheme is currently set in sys.stdout.encoding, in this instance it's
  "UTF-8".</p>
</blockquote>

<pre><code>&gt;&gt;&gt; cu.encode('utf-8')
'\xe4\xb8\xad\xe6\x96\x87' 
</code></pre>

<p>So! how could <code>len(cu)</code> == 2??? Is that because there are two <code>'\u'</code> in it?</p>

<p>But that doesn't make <code>len(su) == 2</code> sense!</p>

<p>Am I missing something?  </p>

<p>I'm using python 2.7.12</p>

<p>The Python <code>unicode</code> type holds <em>Unicode codepoints</em>, and is not meant to be an encoding. How Python does this internally is an implementation detail and not something you need to be concerned with most of the time. They are not UTF-16 code units, because UTF-16 is another codec you can use to encode Unicode text, just like UTF-8 is.</p>

<p>The most important thing here is that a standard Python <code>str</code> object holds <em>bytes</em>, which may or may not hold text encoded to a certain codec (your sample uses UTF-8 but that's not a given), and <code>unicode</code> holds <em>Unicode codepoints</em>. In an interactive interpreter session, it is the codec of your terminal that determines what bytes are received by Python (which then uses <code>sys.stdin.encoding</code> to decode these as needed when you create a <code>u'...'</code> <code>unicode</code> object).</p>

<p>Only when <em>writing to <code>sys.stdout</code></em> (say, when using <code>print</code>) does the <code>sys.stdout.encoding</code> value come to play, where Python will automatically encode your Unicode strings again. Only <em>then</em> will your 2 Unicode codepoints be encoded to UTF-8 again and written to your terminal, which knows how to interpret those.</p>

<p>You probably want to read up about Python and Unicode, I recommend:</p>

<ul>
<li><p><a href="http://nedbatchelder.com/text/unipain.html" rel="nofollow">Pragmatic Unicode</a> by Ned Batchelder</p></li>
<li><p><a href="http://joelonsoftware.com/articles/Unicode.html" rel="nofollow">The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)</a> by Joel Spolsky</p></li>
<li><p>The <a href="http://docs.python.org/2/howto/unicode.html" rel="nofollow">Python Unicode HOWTO</a></p></li>
</ul>

python python-2.7 unicode encoding utf-8