Description of the chr() function

The chr() function in Python returns the string representing a character whose Unicode code point is the integer. For example, chr(97) would return the string 'a'. This function takes a single argument, an integer representing the Unicode code point, and returns a corresponding string. If the code point is out of the range of valid Unicode code points, a ValueError is raised.

Example of use of the chr() function

Here's an example of using the chr() function in Python:

code_point = 65
letter = chr(code_point)
print(letter)

In this example, the variable code_point is set to 65, which is the Unicode code point for the letter 'A'. The chr() function is then used to convert this code point to the corresponding string, 'A'. When the print(letter) statement is executed, it will output the letter 'A' on the screen. You could also use it in a loop to print the alphabets

for i in range(65,91):
print(chr(i),end=' ')
#output: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Younes Derfoufi
my-courses.net

Leave a Reply