Each character in a string is assigned a number. This number is called the index. Check out the diagram in the editor.
c = "cats" n = "Ryan"
- In the above example, we create a new variable called
cand set it to
"c", the character at index zero of the string
- Next, we create a new variable called
nand set it to
"n", the character at index three of the string
Notice that in the first “cat” example we are calling the 0th letter of “cat” and getting “c” in return. This is because in Python indices begin counting at 0. Therefore, in the string “cats”, the first letter, “c”, is at the 0th index and the last letter, “s”, is at the 3rd index.
On line 13, assign the variable
fifth_letter equal to the fifth letter of the string “MONTY”.
Remember that the fifth letter is not at index 5. Start counting your indices from zero.