Home »
Python
chr() function with example in Python
Python chr() function: Here, we are going to learn about the chr() function in Python with example.
Submitted by IncludeHelp, on April 02, 2019
Python chr() function
chr() function is a library function in Python, it is used to get character value from the given ASCII code (integer value), it accepts a number (that should be an ASCII code) and returns the character.
Syntax:
chr(number)
Parameter:number – an ASCII code (integer value) whose character value we want.
Return value: str – returns character (string) value.
Example:
Input:
num = 65
print(chr(num))
Output:
A
Python code to find character value from given ASCII code
# python code to demonstrate an example
# of chr() function
# number (ASCII code of A)
num = 65
print("character value of ", num, " is = ", chr(num))
num = 120
print("character value of ", num, " is = ", chr(num))
num = 190
print("character value of ", num, " is = ", chr(num))
Output
character value of 65 is = A
character value of 120 is = x
character value of 190 is = ¾
ADVERTISEMENT
ADVERTISEMENT