Python Program to find ASCII value of a character or digit

Program

ch = 't'
print "The ASCII value of '" + ch + "' is ", ord(ch)

What is ASCII?

ASCII (American Standard Code for Information Interchange) is a character encoding standard that represents text characters in computers. Each character (letters, digits, symbols) has a unique numeric value (0 to 127).

For example:

  • 'A' → 65
  • 'a' → 97
  • '0' → 48
  • ' ' (space) → 32

Uses of ASCII

  1. Text Processing: Used in files, databases, and programming languages.
  2. Data Transmission: Helps in encoding characters in networking protocols.
  3. Sorting & Comparison: Useful in comparing and sorting strings alphabetically.
  4. Keyboard Input Processing: Converts keypresses into ASCII codes.
  5. Encryption & Encoding: Basis for character-based encoding methods.

Python Program to Find ASCII Value of a Character

ch = 't'
print "The ASCII value of '" + ch + "' is ", ord(ch)
  • A character 't' is assigned to variable ch.
  • ord(ch) returns the ASCII value of the character.
  • The result is printed in a readable format.

Key Takeaways

  • ASCII assigns unique numeric values to characters.
  • The ord() function returns the ASCII value of a given character.
  • Python 2 uses print without parentheses, while Python 3 requires parentheses.

Output

The ASCII value of 't' is  116