chr() Function in Python

Python chr() Function

The chr() function in Python is a built-in function that returns a string representing a character whose Unicode code point is the integer passed as an argument. In simpler terms, it takes an integer and returns the corresponding character.

Here's the syntax of the chr() function:

chr(i)

The i parameter is an integer that represents the Unicode code point of the character you want to retrieve.

Here are a few examples of using the chr() function:

print(chr(65))   # Output: 'A'
print(chr(97))   # Output: 'a'
print(chr(8364)) # Output: '€'

In the first example, chr(65) returns the character 'A' because the Unicode code point 65 corresponds to the uppercase letter 'A'. Similarly, in the second example, chr(97) returns the character 'a' because the code point 97 corresponds to the lowercase letter 'a'. In the third example, chr(8364) returns the character '€' because the code point 8364 represents the Euro symbol.

Keep in mind that the chr() function can only handle integers within the valid Unicode code point range, which is from 0 to 1,114,111 (0x10FFFF) inclusive. Passing an invalid code point will raise a ValueError exception.