89DEVs

Python chr() function

The built-in function chr() returns a character for an integer, which represents the unicode symbol.


# Python chr() example
print(chr(97))
print(chr(65))


The integer 97 represents the unicode symbol 'a' and the integer 65 represents 'A'.


a
A


chr() syntax

The syntax of chr() is: chr(integer)

chr() arguments

The chr() function accepts exactly 1 argument and it has to be an integer. If more or less than one argument is passed, an TypeError exception is raised. If the given integer is out of range, a ValueError exception is raised. The valid range of integers is 0 to 1114111.

chr() return values

The chr() function returns one character as string. The return value is the unicode character represented by the given integer.

Reverse chr() function

To reverse the chr() function use the ord() function. It returns the integer that represents a given unicode character.

                
        

Summary


Click to jump to section