End of Summer - hours only!Up to 80% off on all courses and bundles.-Close
Cipher
2. Function ord()

Instruction

Great! Let's start with the ord() function. The ord() function takes a character as an argument and returns a number.

print(ord('a'))
>> 97

This works because each character has a number assigned to it in what is called Unicode.

Ascii table

Unicode is an international character encoding standard. All possible characters, including characters from the Latin alphabet, like 'a', 'A'; and from national alphabets, like 'ą', or '主' are given a number in Unicode.

The ord() function returns the Unicode number for the given character. For example, ord('a') returns the number 97, which is the number pointing to the character 'a' in Unicode. As you can imagine, we can transform every single character into a number.

Exercise

Create a function that accepts a word as an input and returns a list of ord() values for every letter of that particular word. Name the function return_ord_values(word). E.g., the following code:

return_ord_values('Python')

Should return the below list:

[80, 121, 116, 104, 111, 110]