A London bus display shows a 7. Why might a program use 55 to represent it?
You're waiting for the number seven bus in London. The display shows the digit seven, but the program can represent that character with the number fifty-five. Why fifty-five, and how does the program turn it back into the digit you see?
Start with the string A seven. Its length is two. Position zero gives you A. To take a substring, slice from position one up to, but excluding, position two. That gives you the string seven. Finally, join A seven and B to make A seven B.
Read across the first row. Capital A pairs with sixty-five. The next rows pair B with sixty-six and C with sixty-seven. Each assigned number is a character code. These entries come from Unicode, a shared standard that assigns numbers to characters.
You've seen how to start with a letter and find its code. Now go the other way. If you start with the code sixty-six, which character does the table give you? Pick an answer.
To find the code for capital A in Python, call ord with A in quotes. It returns the integer sixty-five. To go back, call chr with the integer sixty-five. It returns capital A as a one-character string.
Now try the same pair of conversions with the digit seven. Its table entry pairs the character seven with code fifty-five. Which pair of Python calls takes you from the character to its code and back? Pick an answer.
Follow the first line. Ord takes the character seven and stores its Unicode code, fifty-five, in the variable called code. Next, chr reads that integer and stores the matching one-character string, seven, in the variable called digit.
You can pass the string seven to int to get the integer seven, or pass it to ord to get the character code fifty-five. Use the value seven for arithmetic. A common mistake is to say that ord returns seven. It looks up the code, so it returns fifty-five.
If your string contains seven point five, use float to read it as a real number. To go back to text, use str. You can pass it an integer like seven or a float like seven point five. Both results are strings.