🚀 Supercharge your YouTube channel's growth with AI.
Try YTGrowAI FreePython Ord to Char: Convert Code Points

If you have a code point number and want its character, Python lets you convert between the number and text. ord() gets a character’s integer code point, while chr() turns an integer code point into a one-code-point string.
This article shows how to convert in both directions and what happens when ord() receives a string with more than one character.
TL;DR
Use ord() to get a character’s Unicode code point and chr() to build a one-code-point string from an integer.
- ord(“A”) returns 65.
- chr(65) returns “A”.
- These functions work with Unicode code points, not UTF-8 byte sequences.
What Are Python chr() and ord()?
Use ord() to get the integer for a character, then pass that value to chr() when you need the corresponding one-code-point string. Hexadecimal notation such as U+20AC is a readable way to write a code point.
ASCII values cover common English letters, digits, and punctuation. The same functions also handle characters such as the euro sign.
How to Convert Python Characters and Code Points Step by Step
I ran python3 ord_chr_demo.py with familiar letters, a symbol, and longer inputs.
Step 1: Convert a code point integer with chr()
For the numeric input, use an integer accepted by chr().
letter = chr(65)
print(letter, type(letter).__name__)
The output is A str, the Python type used for text values.
Step 2: Get a code point with ord()
Use ord(character) to inspect the numeric value. Formatting the result with X displays uppercase hexadecimal digits.
print(ord("A"))
print(f"U+{ord('€'):04X}")
The results are 65 and U+20AC. The formatted value identifies the euro sign.
Step 3: Check a round trip and the byte boundary
The loop tests letters and a symbol, then deliberately supplies longer strings to expose the input-length error. It also prints encoded bytes beside numeric values.
for character in ["A", "é", "€"]:
codepoint = ord(character)
print(f"{character!r} -> U+{codepoint:04X} -> {chr(codepoint)!r}")
for value in ["Hi", "AB"]:
try:
print(ord(value))
except TypeError as error:
print(f"{value!r}: {error}")
print("A".encode("utf-8"), ord("A"))
print("é".encode("utf-8"), ord("é"))
Running python3 ord_chr_demo.py prints these values and errors:
'A' -> U+0041 -> 'A'
'é' -> U+00E9 -> 'é'
'€' -> U+20AC -> '€'
'Hi': ord() expected a character, but string of length 2 found
'AB': ord() expected a character, but string of length 2 found
b'A' 65
b'\xc3\xa9' 233

These bytes are the UTF-8 encoding of the text. The corresponding ord() result is a code point, as the output shows. For byte conversion, see AskPython’s encode and decode guide.
Edge Cases: Range, String Length, and Bytes
Check the integer range and input length before converting. The table gives the symptom and a direct fix for common mistakes.
To build a string from several known values, call chr() for each integer and join the results. For example, chr(72) + chr(105) produces Hi. This is useful when a data format or exercise gives numeric code points, but ordinary text is clearer when the characters are already known.
Syntax follows the same simple shape: ord(character) accepts a one-code-point str or a one-byte bytes value, while chr(integer) accepts an integer in the Unicode range. The parentheses contain the input, and each call returns a value you can assign, print, or pass to another function.
For a string, loop over its characters instead of passing the whole value to ord(). A comprehension makes a list of code points when that is more convenient: [ord(character) for character in “Hi”] returns [72, 105]. Choose a list when you need to inspect or transform each number, and join chr() results when you need text back.
The first example is a direct round trip. ord(“A”) gives 65, and chr(65) returns “A”. The return value is still a string, so it can be combined with other text without converting the number to bytes.
For a full sentence, do not call ord() once on the entire string because the function accepts one code point per call. Iterate through the text, collect each result, and preserve the order if you later rebuild it. This also helps locate a length error: check the value passed at the point of failure.
| Input | Symptom | What to do |
|---|---|---|
| chr(-1) or chr(0x110000) | ValueError | Keep the integer within 0..0x10FFFF. |
| ord(“Hi”) | TypeError because the string has length 2 | Loop over the string and call ord() for each code point. |
| ord(b”A”) | Returns 65, the single byte’s value | Decode multi-byte text with its known encoding before inspecting characters. |
A displayed grapheme can contain a base letter and combining mark as separate code points. String iteration therefore visits code points, which may differ from the units a reader counts when slicing visible text.
Conclusion
Check the input type before choosing the operation. For byte conversion, see Python string and bytes conversion and the official Python built-in functions documentation.
FAQ
These answers cover returning from a number to text and handling input length.
How do I convert an ord value back to a character in Python?
Pass the integer code point to chr(), such as chr(65), which returns ‘A’.
Does ord() return an ASCII value?
It returns a Unicode code point for a one-code-point string. ASCII values match the first 128 code points, but Unicode includes many more.
Why does ord() reject a string with two characters?
ord() accepts one code point at a time. Iterate over the string and call ord() on each element.


