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
author's image
Abhijeet Pal Author and Editor in Chief @djangocentral

Abhijeet is a full-stack software developer from India with a strong focus on backend and system design. He is driven by the need to create impactful solutions that add value to the internet in any way possible.

LinkedIn Twitter Github

Latest Articles

Latest from djangocentral

Django 4.1 adds async-compatible interface to QuerySet

The much-awaited pull request for an async-compatible interface to Queryset just got merged into the main branch of Django.Pull Request - https://github.com/django/django/pull/14843 The Django core team has been progressively adding async suppor…
Read more →

3 min read

Making Django Admin Jazzy With django-jazzmin

Django admin is undoubtedly one of the most useful apps of Django. Over the years there has been very little change in the admin app as far as the UX is concerned and it's not a bad thing at all. Django admin was designed to provide a simple and minimali…
Read more →

4 min read