Python Program To Find ASCII Value of a character.

Finding the ASCII value of a character in Python programming is useful for solving many coding problems. In this tutorial, we will learn different ways to find the ASCII  value of any given character.

What is ASCII Value?

ASCII, which stands for American Standard Code for Information Interchange, is a character encoding standard used for representing text and control characters in computers and other devices that use text.

In ASCII, each character is assigned a unique numeric value. The standard ASCII set uses values ranging from 0 to 127, representing basic characters such as letters, digits, punctuation, and control characters.

Example:
  • The ASCII value for the uppercase letter 'A' is 65.
  • The ASCII value for the lowercase letter 'a' is 97.
  • The ASCII value for the digit '0' is 48.
  • The ASCII value for the exclamation mark '!' is 33.

Python Code to Find ASCII Value of a Character.

In Python, the ord() function can be used to find the ASCII value of a character.

Here's a simple Python program to get ASCII value:
character = input("Enter a character: ")

# ASCII value of character
ascii_value = ord(char)
print(f"The ASCII value of {character} is {ascii_value}")
Output:
Enter a character: D
The ASCII value of D is 68

The ord() function in Python is a built-in function that returns an integer representing the Unicode character. 

Python Program to Find Character from ASCII Value.

The chr() function is the inverse of ord(). It converts an ASCII value to its corresponding character. 

Here is a simple Python Code to get a Character from an ASCII value:
ascii_value = int(input("Enter an ASCII value: "))

character = chr(ascii_value)

print(f"The character for ASCII value {ascii_value} is {character}")
Output:
Enter an ASCII value: 65
The character for ASCII value 65 is A

These approaches showcase the simplicity and flexibility of Python when working with ASCII values. 


Related post:

⚡ Please share your valuable feedback and suggestion in the comment section below or you can send us an email on our offical email id ✉ algolesson@gmail.com. You can also support our work by buying a cup of coffee ☕ for us.

Similar Posts

No comments:

Post a Comment


CLOSE ADS
CLOSE ADS