Python get ASCII Code for a letter examples| ord, chr function
This tutorial shows you how to convert ASCII to Character and Character to ASCII
Get ASCII Value of an character
ord()
function returns the ASCII value for a given character. It accepts only single character.
asciivalue =ord('a')
print(asciivalue) # 97
print(ord('b')) # 98
print(ord('c')) # 99
print(ord('d')) # 100
in case if ord('abc')
functio passed an string, It throws
TypeError: ord() expected a character, but string of length 3 found
Convert ASCII to Character in python
chr()
function takesn integer value , returns letter.
print(chr(97)) # a
print(chr(98)) # b
print(chr(99)) # c
print(chr(100)) # d