Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • which encoding in chr using ? Commented Dec 14, 2011 at 8:59
  • 25
    Note that chr also acts as unichr in Python 3. chr(31415) -> '窷' Commented Apr 3, 2013 at 13:47
  • 7
    @njzk2: it doesn't use any character encoding it returns a bytestring in Python 2. It is upto you to interpret it as a character e.g., chr(ord(u'й'.encode('cp1251'))).decode('cp1251') == u'й'. In Python 3 (or unichr in Python 2), the input number is interpreted as Unicode codepoint integer ordinal: unichr(0x439) == '\u0439' (the first 256 integers has the same mapping as latin-1: unichr(0xe9) == b'\xe9'.decode('latin-1'), the first 128 -- ascii: unichr(0x0a) == b'\x0a'.decode('ascii') it is a Unicode thing, not Python). Commented Apr 30, 2014 at 2:59
  • 6
    Why is the function called "ord"? Commented Aug 1, 2018 at 17:10
  • 12
    @eLymar: it's short for "ordinal," which has similar linguistic roots to "order" - i.e. the numeric rather than symbolic representation of the character Commented Jan 16, 2019 at 16:30