Python's built-in chr() function converts a decimal ASCII value between 0 and 127 into its corresponding character, with ord() performing the exact reverse operation on a single character. For example, chr(65) returns the string 'A' and chr(97) returns 'a', because those assignments for Latin letters are fixed by IETF RFC 20 and cross-checked against the Unicode C0 Controls and Basic Latin chart. Both functions accept any integer Python can represent, but standard 7-bit ASCII only defines 128 code points covering control characters, punctuation, digits, uppercase and lowercase Latin letters, and DEL. If your source data lists decimal numbers like 65, 97, 48, or 32, chr() will return 'A', 'a', '0', and a space respectively; values such as 128, 200, or 256 still produce a character, but it is not standard ASCII and will not round-trip cleanly through ASCII-aware systems. For readers who prefer to verify conversions without writing a script, a browser-based ASCII Converter accepts text or decimal numbers and applies the same 0-127 boundary with visible errors instead of silent reinterpretation.

how to convert ascii value to character in python
how to convert ascii value to character in python

Python's chr() and ord() Functions

The relationship between chr() and ord() is exact within the 0-127 range: chr(ord(c)) == c and ord(chr(n)) == n for any single character c whose code point falls inside standard ASCII. The two functions are documented as inverse for an 8-bit ASCII string, which corresponds to the seven-bit range plus the high-bit slot at 128 that Python reserves for the start of the Latin-1 supplement. Because Python strings store Unicode code points, chr(200) returns a printable character that does not belong to standard ASCII; this is the most common source of confusion when readers expect chr() to behave like an ASCII-only lookup.

For batch conversion, a list comprehension or generator expression is the standard idiom. The snippet [chr(n) for n in [65, 66, 67]] produces the list ['A', 'B', 'C'], while ''.join(chr(n) for n in [72, 101, 108, 108, 111]) produces the string 'Hello'. The reverse direction uses [ord(c) for c in 'ABC'], which yields [65, 66, 67]. Both idioms rely on Python's ability to pass integers to chr() and to iterate a string character by character with ord(), so they work identically for ASCII, Latin-1, and full Unicode text.

The 0-127 Range and What It Includes

Standard 7-bit ASCII defines exactly 128 assignments, numbered 0 through 127. Codes 0 through 31 and code 127 are the C0 control characters, including 0 (NUL), 9 (TAB), 10 (LF), 13 (CR), and 127 (DEL); these often render with no visible glyph. Code 32 is the space character. Codes 33-47, 58-64, 91-96, and 123-126 cover punctuation and a few symbols such as !, ?, @, and ~. Codes 48-57 are the digits 0 through 9. Codes 65-90 are the uppercase Latin letters A-Z, and codes 97-122 are the lowercase Latin letters a-z.

This fixed mapping is the reason a Python script that uses chr() on values 0-127 behaves identically across operating systems, Python versions, and locales. The same boundary also explains why a tool that promises to convert ASCII must reject or explicitly label anything above 127. The phrase extended ASCII refers to a family of incompatible single-byte encodings such as Windows-1252 and ISO-8859-1, and no silent fallback is acceptable when the input is supposed to be 7-bit ASCII. For the canonical assignment table, see IETF RFC 20 and the Unicode Basic Latin chart.

Convert ASCII Value to Character Using the ASCII Converter

When the conversion needs to happen outside a Python script - for example, when copying a list of decimal codes from a textbook, a debug log, or a colleague's notes - a browser-based tool avoids writing or running any code. The ASCII Converter performs the same 0-127 conversion as chr() and ord(), but enforces the boundary strictly and reports invalid input by position rather than producing a misleading Unicode character.

  1. Choose whether to encode ASCII text or decode decimal ASCII codes.
  2. Enter text or decimal values from 0 to 127 separated by spaces, commas, or line breaks.
  3. Select Convert ASCII, review invisible control-character implications, and copy the result if needed.

Encoding mode turns each character in the input into a space-separated decimal integer, so Hi becomes 72 105. Decoding mode parses a list of integers separated by spaces, commas, or line breaks and reconstructs the exact ASCII string. Because the accepted range is exactly 0 through 127, any token outside that band is rejected along with its position, and the tool does not silently reinterpret values 128-255 as Windows-1252 or ISO-8859-1.

Python Code Examples for Common Conversions

The most common task is a one-to-one lookup. Given a single integer, chr(65) returns 'A'. Given a list of integers, [chr(n) for n in [65, 97, 48, 32]] returns ['A', 'a', '0', ' ']. Joining the result with spaces, commas, or line breaks lets the same list be fed back into a decoder that expects decimal codes. The reverse direction is equally direct: ord('A') returns 65, and [ord(c) for c in 'Python'] returns [80, 121, 116, 104, 111, 110].

When validating an unknown input, an explicit range check keeps the script honest. The pattern if not 0 <= n <= 127: raise ValueError(f'non-ASCII code: {n}') prevents the silent production of Latin-1 or other extended characters. This mirrors the strict validation performed by the ASCII Converter, which rejects the first character outside 7-bit ASCII and reports its position, and which rejects signs, fractions, hexadecimal prefixes, empty tokens, and values above 127 on the decode side.

For more general background on going the other direction - turning the decimal codes into the actual character stream that downstream code expects - the decimal codes to text walkthrough covers the same boundary rules in a non-Python context and pairs naturally with a chr()-based script.

Handling Control Characters and Invalid Values

Codes 0-31 and 127 are controls, not printable characters. Decimal 9 is a tab, 10 is a line feed, 13 is a carriage return, 0 is NUL, and 127 is DEL. When these codes are decoded into a string and pasted into a terminal, editor, or chat window, the receiving application may render them with no glyph, treat them as formatting, or trigger application-specific behavior such as focus changes or shortcut handling. The ASCII Converter surfaces this risk by warning that control codes may be invisible in the output textarea, and recommends using the decimal output or a byte-aware editor when visibility matters.

In Python, the same warning applies whenever a decoded string contains control characters. print(chr(9) + 'x') shows a tab before x; print(repr(chr(0))) shows '\x00' instead of nothing. A safe pattern for verifying that decoding produced the expected code points is to print the result with repr() or to inspect each code with ord() in a loop. This is also the right place to enforce the 0-127 boundary, because chr(128) returns a printable Unicode character that has no place in any ASCII contract.

Python chr() vs ASCII Converter vs Other Tools

Different methods for turning decimal codes into characters trade off between automation, visibility, and strictness. The table below compares the most common approaches so the right tool can be picked for the job.

Method Input format Range supported Output visibility Best for
Python chr() / ord() Integer or single character Strictly 0-127 for ASCII; accepts any Unicode code point Full Unicode glyph Scripts, automation, batch conversion
ASCII Converter Text or decimal numbers in a textarea Strict 0-127 with visible errors Controls may render invisibly Quick verification without writing code
ASCII Table None (static reference) 0-127 displayed Static chart Looking up a single code point
Text to Hex / Binary Text UTF-8 byte sequences, not 7-bit ASCII Hex or binary string Encoding text in another numeric base

For values above 127, chr() returns a Unicode code point that is not standard ASCII, and the ASCII Converter rejects the value outright. The same boundary applies to hex, binary, and Base64 representations: they encode bytes, not ASCII code points, so a separate tool that explicitly names its encoding is required when the input is genuinely outside the 7-bit range. For Unicode code points, UTF-8 bytes, or locale-specific character conversion, the right move is a converter that names the required encoding rather than treating the data as ASCII.