CHR, UNICHR, Ord can be used as character-type conversions in Python, and here we talk about the comparison between CHR, UNICHR, and Ord character functions in Python, and the friends you need can refer to
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.
>>c = U ' kang ' >>cu ' \u5eb7 ' >>ord (c) 24747>>chr (24247) VALUEERROR:CHR () arg not in range > >UNICHR (24247) u ' \u5eb7 '
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.
>>> chr ' a ' >>> ord (' a ') 97>>> unichr (12345) u ' \u3039 ' >>> chr (12345) Traceback ( Most recent call last): File ' <stdin> ', line 1, in? Chr (12345) VALUEERROR:CHR () arg not in range (at >>> 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