In Python, chr(i) returns a string of one character whose Unicode code point is the integer i: chr(65) is "A" and chr(0x20AC) is the euro sign.
It is the inverse of ord(): chr(ord(c)) == c. Valid code points run from 0 to 1,114,111 (0x10FFFF), which covers every Unicode character.
chr() is a built-in function: it lives in the builtins module, so it is always available without an import.
Syntax
Pass an int code point; get back a one-character str.
python
character = chr(code_point)
Call
What it does
chr(65)
Returns "A".
chr(97)
Returns "a".
chr(0x20AC)
Returns "\u20ac", the euro sign.
chr(ord("a") + 1)
Returns "b": the next letter.
Hex literals like 0x20AC match the way Unicode charts write code points (U+20AC).
Library declarations
python
chr(i, /)
# 0 <= i <= 0x10FFFF
Parameters
Parameter
Description
i
Required. An int from 0 to 1,114,111 (0x10FFFF).
Return Value
Return Value
Description
str
A string of length 1 containing the character.
Python Examples
Example 1 — Turn ASCII Codes into Characters
Convert five familiar code points and print each result with repr() so spaces stay visible.
python
for code in [65, 97, 48, 32, 126]:
print(code, repr(chr(code)))
Output
65 'A'
97 'a'
48 '0'
32 ' '
126 '~'
How It Works
Letters. 65 is uppercase A and 97 is lowercase a; the two cases are 32 apart.
Digit characters. 48 is the character "0", not the number zero.
Invisible characters. 32 is a space; repr() wraps it in quotes so you can see it.
One-character strings. Each result is a str of length 1.
Example 2 — Build an Alphabet and a Caesar Shift
Generate letters from a range of code points and shift text by a fixed amount with ord() and chr().
python
def shift(text, n):
result = []
for ch in text:
if "a" <= ch <= "z":
result.append(chr((ord(ch) - ord("a") + n) % 26 + ord("a")))
else:
result.append(ch)
return "".join(result)
letters = "".join(chr(c) for c in range(ord("a"), ord("a") + 5))
print(letters)
print(shift("hello, xyz", 3))
print(shift(shift("hello, xyz", 3), -3))
Output
abcde
khoor, abc
hello, xyz
How It Works
Range of code points.range(97, 102) passed through chr() produces "abcde".
Shift in 0..25. Each letter becomes a position (a = 0), moves by n, and wraps with % 26.
Back to a letter. Adding ord("a") and calling chr() turns the new position into a character, so x, y, z wrap to a, b, c.
Reversible. Shifting by -3 undoes the shift, because Python's % always returns a non-negative result here.
Example 3 — Unicode Code Points and Invalid Values
Create the euro sign and an emoji from their code points, then try values outside the valid range.
python
euro = chr(0x20AC)
print(ascii(euro), hex(ord(euro)))
print(chr(0x1F600) == "\U0001F600")
print(len(chr(0x10FFFF)))
for value in [-1, 0x110000]:
try:
chr(value)
except ValueError:
print(value, "is outside the Unicode range")
try:
chr("A")
except TypeError:
print("chr() needs an int; use ord() for the reverse")
Output
'\u20ac' 0x20ac
True
1
-1 is outside the Unicode range
1114112 is outside the Unicode range
chr() needs an int; use ord() for the reverse
How It Works
Hex code points.chr(0x20AC) is the euro sign; ascii() prints it as \u20ac so any console can show it.
Beyond 16 bits.chr(0x1F600) equals the \U0001F600 escape, and it is still one character long in Python.
Range limits. -1 and 0x110000 (1114112) are outside 0..0x10FFFF, so chr() raises ValueError.
Wrong type. Passing a string raises TypeError; ord("A") is the conversion in the other direction.
Frequently Asked Questions
It converts an integer Unicode code point into the matching one-character string. chr(65) returns "A".
ord(). ord("A") returns 65, and chr(ord(c)) always gives back c.
0x10FFFF, which is 1114111. Larger values and negative values raise ValueError.
Use "".join(chr(c) for c in range(ord("a"), ord("z") + 1)), or simply string.ascii_lowercase from the string module.
The character is valid, but your terminal font or encoding cannot display it. Print ascii(ch) to see its escape instead.