To convert int to char in Python, you can use the chr() function.
It takes an integer argument and returns a string representing a character at that Unicode code point.
If you pass an invalid code point to chr(), it will raise a ValueError.
Visual representation
Example 1: Usage of chr() function
my_int = 70 #ASCII value of F
print(my_int)
print(type(my_int))
# Convert integer to character
my_char = chr(my_int)
print(my_char)
print(type(my_char))
print(chr(65))
print(chr(97))
Output
70
<class 'int'>
F
<class 'str'>
A
a
Example 2: list of integers to characters
# Define a list of ASCII values
my_list = [69, 72, 78, 81, 90, 99]
# Iterate through the list and convert each number to its corresponding character
for number in my_list:
my_char = chr(number)
print("Character of ASCII value", number, "is", my_char)
Output
Character of ASCII value 69 is E
Character of ASCII value 72 is H
Character of ASCII value 78 is N
Character of ASCII value 81 is Q
Character of ASCII value 90 is Z
Character of ASCII value 99 is c
That’s it.