The CHR () function returns a corresponding character by using an integer (that is, 0~255) within range (256) as a parameter.
UNICHR () is just like it, except that the Unicode character is returned, and the parameter range of the UNICHR () added from Python 2.0 depends on how your Python is compiled. If it is configured to USC2 Unicode, then it is allowed to range (65536) or 0X0000-0XFFFF, if configured as UCS4, then this value should be range (1114112) or 0x000000-0x110000. If the supplied parameter is not within the allowable range, a ValueError exception is reported
The Ord () function is the Chr () function (for 8-bit ASCII strings) or the UNICHR () function (for Unicode objects), which returns the corresponding ASCII value, or Unicode value, as a parameter with a character (a string of length 1). If the given Unicode character exceeds your Python definition range, a TypeError exception is thrown.
- ORD is the abbreviation for Unicode ordinal, which is the number
- CHR is the abbreviation of character, which is the character
- Ord and CHR are reciprocal conversions.
- However, because CHR is limited to ASCII, the length is only 256, so more a unichr.
>>> Chr (69)'E'>>> Ord ("A")65>>> UNICHR (500) U'\u01f4'>>>PrintUNICHR (500) Traceback (most recent): File"<stdin>", Line 1,inch<module>Unicodeencodeerror:'GBK'Codec can'T encode character u'\u01f4'In position 0:illegal multibyte sequence#can be encode into UTF8 output when all encoding formats fail to pass>>>PrintUNICHR (+) encode ("Utf-8") Punished>>> A=u'Punished'>>>Ord (a)35892>>> a='Punished'>>>Ord (a) Traceback (most recent): File"<stdin>", Line 1,inch<module>Typeerror:ord () expected a character, but string of length2found>>> Chr (35892) Traceback (most recent): File"<stdin>", Line 1,inch<module>VALUEERROR:CHR () arg not inchRange (256)>>> UNICHR (35892) U'\u8c34'>>>PrintUNICHR (35892). Encode ("Utf-8") Zhang>>>PrintUNICHR (35892). Encode ("GBK") Punished
Python Chr () ord () UNICHR ()