Skip to content

Python chr() Function

  • by

Python chr() Function is used to convert an integer to its Unicode character. This function returns a string from a Unicode code integer.


number: An integer representing a valid Unicode code point

ValueError – for an out-of-range integer number

TypeError – for a non-integer argument

Python chr()

Simple example code.

print(97, chr(97))
print(65, chr(65))
print(1200, chr(1200))


Python chr() Function

Printing characters for each Unicode integer in the numbers list.

numbers = [101, 111, 110]

for number in numbers:
    letter = chr(number)
    print("ASCII value", number, "is ", letter)


ASCII value 101 is e
ASCII value 111 is o
ASCII value 110 is n

The chr() only accepts integers within the valid Unicode range (0 through 1,114,111). If you pass an integer outside this range, ValueError will be raised.

Do comment if you have any doubts or suggestions on this Python function topic.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Your email address will not be published. Required fields are marked *