Search code examples
pythonunicodeasciibuilt-inchr

Is there any specific reason why the chr function won't accept a higher answer?


Does anybody know if there is a specific reason why the chr function throws an error if I enter a number higher than 1114111? EG:

>>> chr(1114111)
'\U0010ffff'
>>> chr(1114112)

Traceback (most recent call last): File "", line 1, in chr(1114112) ValueError: chr() arg not in range(0x110000)


Solution

  • Yes, there is a specific reason. It's because that's the highest code point in the Unicode code space. From the current standard (12.0), section 1.3 Text handling, under Text elements:

    An encoded character is represented by a number from 0 to 10ffff16, called a code point.