Python Program To Get ASCII Value Of A Character

ASCII, abbreviated from American Standard Code for Information Interchange, is a character encoding standard for electronic communication. ASCII codes represent text in computers, telecommunications equipment, and other devices.

Problem Definition

1] Create a Python Program to get the ASCII value of a given character.

Solution

The ord() function in Python accepts a string of length 1 as an argument and returns the Unicode code point representation of the passed argument, and for the first 128 Unicode code point values are the same as ASCII.

print(ord('a'), ord('b'), ord('c'))

Output

97 98 99

2] Create a Python Program to get the ASCII value of a user-provided character.

character = input("Enter the character")
print("The ASCII code for {} is {}".format(character, ord(character)))

Output

Enter the character a
The ASCII code for a is 97

Problem Definition

1] Create a Python Program to get the character from the given ASCII value.

Solution

The chr() function in Python accepts a Unicode code point as an argument and returns the character pointing to that.

print(chr(97),chr(98))

Output

a b

2] Create a Python Program to get the character from the user-provided ASCII value in runtime.

ascii_code = int(input("Enter The ASCII code"))
print("The character is {}".format(chr(ascii_code)))

Output

Enter The ASCII code 97
The character is a

 

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Close