Python – Program to find ASCII value of a character

Python – Program to find ASCII value of a character

In this post, we will write a Python program for how to find ASCII value.
First, let’s see What is ASCII value?
In programming languages, the characters (variable) holds ASCII value which is an integer number rather than that character itself is known as the ASCII value of character.

ASCII stands for American Standard Code for Information Interchange.

We are going to use built-in ord() function in python to find the ASCII value or integer value of character. This function returns the number that is representing the Unicode of the specified character.
Syntax:

ord(char) 
Where char can be any character.

Examples:

Input: A
Output: The ASCII value of character A is: 65

Input: e
Output: The ASCII value of a character e is: 101

Let’s see the program for this:

# maine code
if __name__ == "__main__" :

    # input the character
    ch = 'k'

    # printing the ASCII value
    # using ord function
    print (f"The ASCII value of character {ch} is:",
           ord(ch))	

    # input the character
    ch = 'K'

    # printing the ASCII value
    # using ord function
    print (f"The ASCII value of character {ch} is:",
           ord(ch))

Output:

The ASCII value of character k is: 107
The ASCII value of character K is: 7

For knowing more about ASCII value, click here : https://www.ascii-code.com/

2 Comments

Leave a Reply

Your email address will not be published.