The chr() function in Python is a built-in function used to convert an integer (Unicode code point) into its corresponding character. In simple terms, it returns the character represented by a given ASCII or Unicode value.
Computers store characters internally as numeric codes, and the chr() function helps convert those numeric codes into readable characters.
chr(number)
print(chr(65))
Output
A
Explanation
print(chr(97))
Output
a
Explanation
print(chr(36))
Output
$
Explanation
print(chr(9731))
Output
☃
Explanation
for i in range(65, 71):
print(chr(i))
Output
A
B
C
D
E
F
Explanation
chr() and ord()| Function | Purpose |
|---|---|
chr() |
Converts a Unicode number to a character |
ord() |
Converts a character to its Unicode number |
Example:
print(chr(65))
print(ord('A'))
Output:
A
65
chr() is a built-in Python function used to convert a Unicode number into a character.