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

Example: Print the character that represents unicode ’65’

x = chr(65)
print(x)	# A

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

Example:

x = chr(97)
print(x)	# a
x = chr(8364)
print(x)	# €

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

Example:

# hex
x = chr(0x24)
print(x)	# $
# octal
x = chr(0o44)
print(x)	# $
# binary
x = chr(0b100100)
print(x)	# $

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

Example:

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