chr() is a built-in Python function that converts an integer (Unicode code point) to its corresponding single-character string — the inverse of ord(). It accepts integers from 0 to 1114111 (0x10FFFF), covering the entire Unicode range. In 2026, chr() remains essential in data science (character encoding, text generation, emoji handling), software engineering (string building, binary-to-text conversion), and functional pipelines — used in cryptography, terminal UI, NLP tokenization, and generating Unicode sequences for testing or visualization.
Here’s a complete, practical guide to using chr() in Python: basic conversion, Unicode ranges, real-world patterns (earthquake symbol generation, text encoding, emoji sequences), and modern best practices with type hints, error handling, performance, and integration with Dask/Polars/pandas/NumPy.
Basic chr() usage — integer to single-character string.
print(chr(65)) # 'A' (ASCII uppercase A)
print(chr(97)) # 'a' (ASCII lowercase a)
print(chr(8364)) # '€' (Euro sign)
print(chr(128512)) # '?' (grinning face emoji)
print(chr(0x1F30D)) # '?' (globe showing Europe-Africa)
print(chr(9733)) # '?' (black star)
Unicode ranges & limits — what chr() supports.
# Basic Latin (ASCII) — 0–127
print(''.join(chr(i) for i in range(65, 91))) # 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
# Extended Latin — accented letters
print(chr(192), chr(193), chr(194)) # 'À' 'Á' 'Â'
# Emoji & symbols — supplementary planes
print(chr(0x1F30E), chr(0x1F30F)) # '?' '?'
# Invalid values raise ValueError
try:
chr(1114112) # > 0x10FFFF
except ValueError as e:
print(e) # chr() arg not in range(0x110000)
Real-world pattern: earthquake data visualization — generate magnitude symbols or Unicode maps.
import pandas as pd
# Sample earthquake DataFrame
df = pd.DataFrame({
'mag': [4.2, 5.8, 6.5, 7.1, 8.0],
'place': ['California', 'Japan', 'Chile', 'Indonesia', 'Alaska']
})
# Map magnitude to intensity symbol (Unicode)
def mag_to_symbol(mag: float) -> str:
if mag < 5: return chr(0x1F7E6) # blue circle
if mag < 6: return chr(0x1F7E5) # yellow circle
if mag < 7: return chr(0x1F7E8) # orange circle
if mag < 8: return chr(0x1F7E9) # red circle
return chr(0x1F525) # fire emoji
df['intensity'] = df['mag'].apply(mag_to_symbol)
# Generate simple magnitude bar using Unicode blocks
df['bar'] = df['mag'].apply(lambda m: ''.join(chr(9608) * int(m)))
print(df[['mag', 'place', 'intensity', 'bar']])
Best practices for chr() in Python & data workflows. Use chr() for Unicode generation — symbols, emojis, special chars. Modern tip: use Polars — pl.col('code').map_elements(chr) — fast column-wise; Dask for distributed arrays. Prefer chr() over manual escape sequences — clearer for Unicode. Validate range — catch ValueError for > 0x10FFFF. Add type hints — def code_to_char(code: int) -> str: return chr(code). Use in string building — ''.join(chr(i) for i in range(65, 91)). Use with ord() — round-trip conversion. Use in formatting — f"Mag: {chr(0x1F525)} {mag:.1f}". Profile performance — chr() is fast; avoid in ultra-tight loops. Use unicodedata — for name/category info: unicodedata.name(chr(8364)) ? 'EURO SIGN'. Use emoji library — for emoji handling. Use chr() in terminal UI — ANSI colors/symbols. Use binascii — for hex/binary conversions. Use struct — for packing/unpacking binary data. Use bytes([65]) — bytes literal alternative.
chr() converts Unicode code points (0–1114111) to single-character strings — perfect for generating symbols, emojis, accented letters, and special characters. In 2026, use for visualization, text encoding, feature engineering, and integrate with pandas/Polars/Dask for array/column operations. Master chr(), and you’ll handle Unicode generation cleanly and efficiently in any Python workflow.
Next time you need to turn a number into a character — use chr(). It’s Python’s cleanest way to say: “Give me the character for this code point — any Unicode char, instantly.”