The CHR () function uses a range (0 to 256 ~ 255) an integer is used as a parameter and a corresponding character is returned. Unichr () is the same as it, but only returns Unicode characters. The parameter range of unichr () added from Python 2.0 depends on how your python is compiled. If Unicode is configured as USC2, the allowed range is range (65536) or 0x0000-0xffff. If it is configured as ucs4, the value should be range (1114112) or 0x000000-0x110000. If the provided parameter is not within the permitted range, a valueerror exception is reported.
The ord () function is a paired function of the CHR () function (for an 8-bit ASCII string) or unichr () function (for a unicode object, it takes a single character (a string with a length of 1) as a parameter and returns the corresponding ASCII value or Unicode value. If the Unicode character is out of your python defined range, A typeerror exception is thrown.
>>> CHR (65)
'A'
>>> Ord ('A ')
97
>>> Unichr (12345)
U' \ u3039'
>>> CHR (1, 12345)
Traceback (most recent call last ):
File "<stdin>", line 1, in?
CHR (1, 12345)
Valueerror: CHR () Arg not in range (256)
>>> Ord (U' \ ufffff ')
Traceback (most recent call last ):
File "<stdin>", line 1, in?
Ord (U' \ ufffff ')
Typeerror: ord () expected a character, but string of length 2 found
>>> Ord (U' \ u2345 ')
9029
CHR (), unichr (), and ord ()