Python chr() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Built-in

Definition

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)
CallWhat 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

ParameterDescription
iRequired. An int from 0 to 1,114,111 (0x10FFFF).

Return Value

Return ValueDescription
strA 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)))

How It Works

  1. Letters. 65 is uppercase A and 97 is lowercase a; the two cases are 32 apart.
  2. Digit characters. 48 is the character "0", not the number zero.
  3. Invisible characters. 32 is a space; repr() wraps it in quotes so you can see it.
  4. 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))

How It Works

  1. Range of code points. range(97, 102) passed through chr() produces "abcde".
  2. Shift in 0..25. Each letter becomes a position (a = 0), moves by n, and wraps with % 26.
  3. 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.
  4. 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")

How It Works

  1. Hex code points. chr(0x20AC) is the euro sign; ascii() prints it as \u20ac so any console can show it.
  2. Beyond 16 bits. chr(0x1F600) equals the \U0001F600 escape, and it is still one character long in Python.
  3. Range limits. -1 and 0x110000 (1114112) are outside 0..0x10FFFF, so chr() raises ValueError.
  4. 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.

Next: classmethod()

Define a method that receives the class (cls).

classmethod() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful