In this article, you will learn how to use the Python chr() function.
Python chr() Function
The Python chr() function is a built-in function that converts an integer Unicode code point to its corresponding Unicode character.
Here’s the syntax of the chr() function:
i: The integer Unicode code point you want to convert to its corresponding Unicode character.
Here’s an example:
>>> print(chr(65)) A
In the example above, we passed the integer value 65 to the chr() function, which corresponds to the Unicode code point for the character “A”. The function returns the Unicode character as a string.
You can also use the ord() function to convert a Unicode character to its corresponding Unicode code point. Here’s an example:
>>> print(ord('A')) 65
In the example above, we passed the character “A” to the ord() function, which returns the Unicode code point as an integer.
Note that chr() and ord() functions work with Unicode code points, which are different from ASCII codes. While the first 128 Unicode code points correspond to the ASCII codes, there are many more Unicode code points that represent characters from other writing systems.