DEV Community

Cover image for Learn ASCII with Easy Examples in Python and JavaScript
Harini
Harini

Posted on

Learn ASCII with Easy Examples in Python and JavaScript

What is ASCII?

ASCII (American Standard Code for Information Interchange) is a character encoding system used to represent text in computers using numbers.

Each character—such as letters (A–Z, a–z), digits (0–9), and symbols (@, #, etc.)—is assigned a unique numeric value called an ASCII value.

Example

  • 'A' → 65
  • 'a' → 97
  • '1' → 49
  • '@' → 64

Why ASCII is Important

  • Helps computers store and process text
  • Used in programming and string manipulation
  • Foundation for modern encoding systems like Unicode

JavaScript

let name = "silambu9391a@gmail.com";

for (let i = 0; i < name.length; i++) {
    console.log(name[i] + " : " + name.charCodeAt(i));
}
Enter fullscreen mode Exit fullscreen mode

How it works

  • name[i] -> gets the character
  • name.charCodeAt(i) -> gets ASCII value of that character

Python

name = "silambu9391a@gmail.com"

for ch in name:
    print(ch, ":", ord(ch))
Enter fullscreen mode Exit fullscreen mode

How it works

  • for ch in name → loops through each character
  • ord(ch) → gives ASCII value of that character

Output

Top comments (0)