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

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

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 *

Python Tutorial

Introduction

  • Python Tutorial
  • Python Introduction
  • Install Python
  • PyCharm IDE Installation
  • Python in PyCharm
  • Python Comments
  • Python Variables
  • Python Keywords & Identifiers
  • Python data types

Flow Control

  • Python If
  • Python if..else
  • Python if..elif..else
  • Python Nested If
  • Python for loop
  • Python while loop
  • Python break
  • Python continue
  • Python pass

Python Functions

  • Python Functions
  • Python Recursion

Python Datatypes

  • Python Numbers
  • Python List
  • Python Strings
  • Python Tuple
  • Python Dictionary
  • Python Set

Python OOPs

  • Python OOP
  • Python Class & Object
  • Python Constructors

Python Examples

  • Python Programs

Copyright © 2012 – 2023 BeginnersBook . Privacy Policy . Sitemap