Python built-in functions (10) -- chr, python built-in function chr
English document:
-
chr( I)
-
Return the string representing a character whose Unicode code point is the integer I. For example,
chr(97)Returns the string 'a', While chr(8364)Returns the string '€'. This is the inverse ord().
-
The valid range for the argument is from 0 through 1,114,111 (0x10FFFF in base 16 ).
ValueErrorWill be raised if IIs outside that range
-
Note:
-
1. The function returns the string representation of the Unicode Character corresponding to the integer parameter value.
>>> Chr (97) # The parameter type is an integer 'A'> chr ('97 ') # The Traceback (most recent call last) error is returned when the parameter is input ): file "<pyshell #6>", line 1, in <module> chr ('97 ') TypeError: an integer is required (got type str) >>> type (chr (97) # The return type is a string <class 'str'>
2. Its functions are just the opposite of the ord functions.
>>> chr(97)'a'>>> ord('a')97
3. The value range of the input parameter must be 0-1114111 (0x10FFFF in hexadecimal format). OtherwiseValueError
>>> Chr (-1) # Traceback (most recent call last): File "<pyshell #10>", line 1, in <module> chr (-1) ValueError: chr () arg not in range (0x110000) >>> chr (1114111) '\ u0010ffff' >>> chr (1114112) # Traceback (most recent call last): File "<pyshell #13>", line 1, in <module> chr (1114112) ValueError: chr () arg not in range (0x110000)