Python Program To Get ASCII Value Of A Character

1 min read

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

 


PROGRAMS

Latest Articles

Latest from djangocentral

Capturing Query Parameters of request.get in Django

In Django, the request object contains a variety of information about the current HTTP request, including the query parameters. Query parameters are a way to pass additional information in the URL and are used to filter or sort data. The request object p…
Read more →

2 min read

Understanding related_name in Django Models

In Django, related_name is an attribute that can be used to specify the name of the reverse relation from the related model back to the model that defines the relation. It is used to specify the name of the attribute that will be used to access the relat…
Read more →

2 min read