-1

I'm trying to represent the copyright symbol © in Python.

If I type © into python interactive terminal I get '\xc2\xa9'. This is 169 and 194 in hexadecimal.

But if I look up the copyright symbol in the unicode table it's only 169.

Python Interactive Terminal:

ord(u"©") --> 169

However '\xa9' == "©" --> False

Only '\xc2\xa9' == "©" --> True

I don't really get why 169 194 together gives copyright instead of just 169 or just 194.

1 Answers1

0

Your terminal supports UTF-8 encoding, and you are likely using Python 2:

>>> import sys
>>> sys.stdout.encoding
'utf-8'
>>> '©'
'\xc2\xa9'
>>> u'©'
u'\xa9'

Python 2 uses byte strings and characters are encoded in the terminal's encoding. Use a Unicode string to get the Unicode value.

Mark Tolonen
  • 166,664
  • 26
  • 169
  • 251