Tutorial Study Image

Python chr()

The chr() function in python takes as a parameter an integer and outputs the corresponding Unicode character


chr(i) #where i is an integer in the range 0 to 1,114,111
 

chr() Parameters:

The chr() function only takes an integer number as a parameter and returns the corresponding character

Parameter Description Required / Optional
An integer The integer must be in the
range of 0 to 1,114,111
Required

chr() Return Value
 

The return value is always a Unicode string

Input Return Value
Integer Returns a Unicode character

Examples of chr() method in Python

Example 1: Passing an integer within the range


print(chr(64))
print(chr(65))
print(chr(100))
 

Output:


@ 
A
d

Example 2: Passing an integer out of range


print(chr(-1))
print(chr(1114112))
 

Output:


ValueError: chr() arg not in range(0x110000) 
ValueError: chr() arg not in range(0x110000)