Menu

ASCII stands for American Standard Code for Information Interchange. It is a character set: a standard list that gives every character a unique code. It is not a programming language or an encryption method. It was originally developed for the English alphabet and is used worldwide for representing text.

Standard ASCII uses 7 bits for each character, and every character code is the same length. With 7 bits there are 2 to the power of 7 = 128 possible codes, so standard ASCII can represent 128 different characters. These include uppercase letters, lowercase letters, digits, punctuation marks and the space character. A capital letter and its lowercase version are different characters with different codes. For example, the question mark ? has the code 63, which is 0111111 as a 7-bit pattern.

A string holds one ASCII code for each character, so you can work through it and look up every code in turn.

word = "Saturn"
for character in word:
    print(character + " has code " + str(ord(character)))

Output:

S has code 83
a has code 97
t has code 116
u has code 117
r has code 114
n has code 110

ASCII is effective because it is a standard: text data can be exchanged between different computer systems and manufacturers, and each system interprets the same code as the same character.

A version of ASCII that uses 8 bits for each character is called extended ASCII. It is a different character set from standard ASCII, which is always 7 bits per character, so an 8-bit code is not standard ASCII.

Practise this