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.

chr(number)

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))

Output:

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)

Output:

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

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 *