Support Our Site

To ensure we can continue delivering content and maintaining a free platform for all users, we kindly request that you disable your adblocker. Your contribution greatly supports our site's growth and development.

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

How to Use Subquery() in Django With Practical Examples

In the realm of web development, Django stands as a powerful and versatile framework for building robust applications. One of the key aspects of developing efficient and optimized web applications is handling database queries effectively. In this article…
Read more →

4 min read

DRF Serializer: Handling OrderedDict and Converting It to a Dictionary or JSON

In Django Rest Framework (DRF) tests, when you access serializer.data, you might encounter an OrderedDict instead of a regular dictionary. This behavior is intentional and reflects the design of DRF's serialization process.Understanding the Problem The u…
Read more →

3 min read

Django Rest Framework CheetSheet: Mastering API Development

Django Rest Framework (DRF) is a powerful toolkit that makes building robust and scalable web APIs with Django a breeze. Whether you're a seasoned Django developer or a newcomer, having a comprehensive cheat sheet at your disposal can be a game-changer. …
Read more →

5 min read

How to Perform NOT Queries in Django ORM

In Django, performing NOT queries allows you to exclude certain records from the query results based on specific conditions. The NOT operator, represented by the tilde (~) when used in conjunction with the Django ORM's Q object, helps you construct compl…
Read more →

3 min read