Python chr()

The chr() method returns a character (a string) from an integer (represents unicode code point of the character).

The syntax of chr() is:

chr(i)

chr() Parameters

The chr() method takes a single parameter, an integer i.

The valid range of the integer is from 0 through 1,114,111.


Return Value from chr()

The chr() returns:

  • a character (a string) whose Unicode code point is the integer i

If the integer i is outside the range, ValueError will be raised.


Example 1: How chr() works?

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

When you run the program, the output will be:

a
A
Ұ

Example 2: Integer passed to chr() is out of the range

print(chr(-1))

When you run the program, ValueError is raised.

It's becauase the argument passed to the chr() method is out of the range.