python u'\u00b0' returns u'\xb0'. Why?
<p>I use python 2.7.10.</p>

<p>On dealing with character encoding, and after reading a lot of stack-overflow etc. etc. on the subject, I encountered this behaviour which looks strange to me. Python interpreter input</p>

<pre><code>&gt;&gt;&gt;u'\u00b0'
</code></pre>

<p>results in the following output:</p>

<pre><code>u'\xb0'
</code></pre>

<p>I could repeat this behaviour using a dos window, the idle console, and the wing-ide python shell.</p>

<p>My assumptions (correct me if I am wrong):
The "degree symbol" has unicode 0x00b0, utf-8 code 0xc2b0, latin-1 code 0xb0.
Python doc say, a string literal with u-prefix is encoded using unicode.</p>

<p>Question: Why is the result converted to a unicode-string-literal with a byte-escape-sequence which matches the latin-1 encoding, instead of persisting the unicode escape sequence ?</p>

<p>Thanks in advance for any help.</p>

<p>Python uses some rules for determining what to output from <code>repr</code> for each character. The rule for Unicode character codepoints in the 0x0080 to 0x00ff range is to use the sequence <code>\xdd</code> where <code>dd</code> is the hex code, at least in Python 2. There's no way to change it. In Python 3, all printable characters will be displayed without converting to a hex code.</p>

<p>As for why it looks like Latin-1 encoding, it's because Unicode started with Latin-1 as the base. All the codepoints up to 0xff match their Latin-1 counterpart.</p>

python unicode character-encoding python-2.x string-literals