Python chr()

In this post, we will see about Python chr() method.
Python chr() method returns a single character String which represens unicode code point of the character.



a single String character


If you pass 65, you will get ‘A’ and if you pass 97, you will get ‘a’.
Let’s see a very simple example:

print('Unicode char of 97',chr(97)) print('Unicode char of 65',chr(65)) print('Unicode char of 6545',chr(6545))


Unicode char of 97 a
Unicode char of 65 A
Unicode char of 6545 ᦑ

here int value can range from 0 through 1,114,111 (0x10FFFF in base 16) and if you provide input which is out of range, it will give you valueError.
Let’s see with the help of example.

print('Unicode char of 1114113',chr(1114113))


ValueError Traceback (most recent call last)
in ()
—-> 1 print(‘Unicode char of 1114113’,chr(1114113))

ValueError: chr() arg not in range(0x110000)

That’s all about Python chr() function.

Leave a Reply

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