Home »
Python
Return value of chr(ord('A')) in Python
Python example of chr() and ord() functions: Here, we are going to learn about the functions chr() and ord() functions in python.
By IncludeHelp Last updated : August 22, 2023
Python ord() function
The ord() function is a library function in Python, it accepts a character and returns it's ASCII value.
Example
print(ord('A')) //returns 65
Python chr() function
The chr() function is a library function in Python, it accepts a value (ASCII code) and returns characters.
Example
print(chr(65)) //returns A
Return value of chr(ord('A'))
Statement chr(ord('A')) evaluation – ord('A') will return 65 and then chr(65) will return character value of ASCII code 65, thus, it will return 'A'.
Python code to demonstrate example of chr() and ord() functions
# python code to demonstrate example of
# chr() and ord() function
# printing ASCII codes
c = 'A'
print("ASCII value of " + c + " is = ", ord(c))
c = 'X'
print("ASCII value of " + c + " is = ", ord(c))
c = 'a'
print("ASCII value of " + c + " is = ", ord(c))
c = 'z'
print("ASCII value of " + c + " is = ", ord(c))
# printing characters
val = 65
print("CHAR value of ", val, " is = " + chr(val))
val = 88
print("CHAR value of ", val, " is = " + chr(val))
val = 97
print("CHAR value of ", val, " is = " + chr(val))
val = 122
print("CHAR value of ", val, " is = " + chr(val))
# chr(ord('A')
print("value of the statement is: " + chr(ord('A')))
Output
ASCII value of A is = 65
ASCII value of X is = 88
ASCII value of a is = 97
ASCII value of z is = 122
CHAR value of 65 is = A
CHAR value of 88 is = X
CHAR value of 97 is = a
CHAR value of 122 is = z
value of the statement is: A