chr()
chr(i) Returns:
str · Added in v3.0 · Updated March 13, 2026 · Built-in Functions built-in unicode string conversion
The chr() function returns a string representing a character whose Unicode code point is the integer i. It is the inverse of ord(), which takes a character and returns its code point.
Syntax
chr(i)
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
i | int | — | An integer representing a valid Unicode code point (0 to 1,114,111) |
Examples
Basic usage
# Get character for ASCII values
print(chr(65)) # A
print(chr(97)) # a
print(chr(48)) # 0
# Get character for Unicode code points
print(chr(8364)) # € (Euro sign)
print(chr(128512)) # 😀 (Grinning face emoji)
Converting with ord()
chr() and ord() are inverses of each other:
char = "A"
code = ord(char)
back = chr(code)
print(f"{char} -> {code} -> {back}") # A -> 65 -> A
Generating a range of characters
# Print all uppercase letters
for i in range(65, 91):
print(chr(i), end=" ")
# A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
# Generate ASCII art pattern
pattern = [chr(95) * 5, chr(47) + chr(92) + chr(124) * 3 + chr(47)]
print("\n".join(pattern))
# _____
# /||||
Common Patterns
Building strings from code points
# Convert a list of code points to a string
code_points = [72, 101, 108, 108, 111]
message = "".join(chr(cp) for cp in code_points)
print(message) # Hello
# Unicode escape to character
hex_codes = [0x0041, 0x0042, 0x0043]
print("".join(chr(c) for c in hex_codes)) # ABC
Working with emoji and special characters
# Generate emoji sequence
emojis = [chr(0x1F600 + i) for i in range(10)]
print(" ".join(emojis))
# 😀 😃 😄 😁 😅 😂 🙂 🙃 😉 😎
# Currency symbols
currencies = [chr(8364), chr(163), chr(165), chr(8359)]
print(" ".join(currencies)) # € £ ¥ ₩
Errors
- ValueError: Raised if
iis outside the valid range (0 to 1,114,111).
chr(-1) # ValueError: chr() arg not in range(0x110000)
chr(1114112) # ValueError: chr() arg not in range(0x110000)
See Also
- built-in::ord — return the Unicode code point of a character
- built-in::ascii — return ASCII representation of an object
- built-in::repr — return string representation of an object