Examples of the chr unichr ord function in python, unichrord
Examples of the chr unichr ord function in python
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(12345) Traceback (most recent call last): File "<stdin>", line 1, in ? chr(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
The above is an introduction to the common Python function chr unichr ord. If you have any questions, please leave a message or go to the community on this site for discussion. Thank you for reading this article and hope to help you. Thank you for your support for this site!