BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

Python Program to Find ASCII Value of a Character

Last Updated: March 27, 2019 by Chaitanya Singh | Filed Under: Python Examples

In this tutorial, we will see how to find the ASCII value of a character. To find the ASCII value of a character, we can use the ord() function, which is a built-in function in Python that accepts a char (string of length 1) as argument and returns the unicode code point for that character. Since the first 128 unicode code points are same as ASCII value, we can use this function to find the ASCII value of any character.

Program to find the ASCII value of a character

In the following program, user enters the character and the program returns the ASCII value of input character.

# Program to find the ASCII value of a character

ch = input("Enter any character: ")

print("The ASCII value of char " + ch + " is: ",ord(ch))

Output:
Python Program to Find ASCII Value of a Character

Program to find the character from a given ASCII value

We can also find the character from a given ASCII value using chr() function. This function accepts the ASCII value and returns the character for the given ASCII value.

# Program to find the character from an input ASCII value

# getting ASCII value from user
num = int(input("Enter ASCII value: "))
print(chr(num))

# ASCII value is given
num2 = 70
print(chr(num2))

Output:
Program to find the character from a given ASCII value

Related Python Examples

1. Python program to find sum of n natural numbers
2. Python program to add digits of a number
3. Python program to convert decimal to hexadecimal
4. Python program to print calendar

Top Related Articles:

  1. Python Program to Print Calendar
  2. Python Program to Check if a Number is Positive Negative or Zero
  3. Python Program to Convert Celsius To Fahrenheit and Vice Versa
  4. Python Program to Convert Decimal to Hexadecimal
  5. Python Program to Find Largest among Three Numbers

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Leave a Reply Cancel reply

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

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap