Python chr() Function

Returns the Unicode character

Usage

The chr() function returns the character that represents the specified number (unicode code point). The valid range for the number is from 0 to 1,114,111 (0x10FFFF).

ValueError will be raised if you specify number outside that range.

You can convert it back to unicode using the ord() function.

Syntax

chr(number)

Python chr() function parameters
ParameterConditionDescription
numberRequiredAn integer representing a valid Unicode code point

Examples

# Print the character that represents unicode '65'
x = chr(65)
print(x)
# Prints A

You can pass any unsigned integer (within 0 to 1,114,111) to the function.

x = chr(97)
print(x)
# Prints a

x = chr(8364)
print(x)
# Prints €

You can also specify number in hexadecimal, octal, and binary formats.

# hex
x = chr(0x24)
print(x)
# Prints $

# octal
x = chr(0o44)
print(x)
# Prints $

# binary
x = chr(0b100100)
print(x)
# Prints $

ValueError will be raised if you specify number outside the range.

x = chr(0xFFFFFFF)
print(x)
# Triggers ValueError: chr() arg not in range(0x110000)