The chr() function converts an integer to its unicode character and returns it.
Syntax
chr(number)chr() Parameters
Python chr() function parameters:
| Parameter | Condition | Description |
|---|---|---|
number |
Required | An integer representing a valid Unicode code point |
chr() Return Value
Python chr() function returns a unicode character of the corresponding integer argument (in the range 0 to 1,114,111).
Examples
Example 1: chr() function with Integer Numbers
print(chr(51)) # 51 to unicode = 3
print(chr(65)) # 65 to unicode = A
print(chr(1200)) # 1200 to unicode = Ұoutput
3
A
ҰExample 2: chr() function with an Out-of-Range Integer
print(chr(-1000))
print(chr(1114113))Both of them will raise a ValueError exception as follows
ValueError: chr() arg not in range(0x110000)Example 3: chr() function with Non-Integer Arguments
print(chr('Tom'))
print(chr('Ryan'))Both of them will raise a TypeError exception as follows
TypeError: an integer is required (got type str)