Learn
Great work!
Each character in a string is assigned a number. This number is called the index. Check out the diagram in the editor.
c = "cats"[0] n = "Ryan"[3]
- In the above example, we create a new variable called
c
and set it to"c"
, the character at index zero of the string"cats"
. - Next, we create a new variable called
n
and set it to"n"
, the character at index three of the string"Ryan"
.
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.
Instructions
1.
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.
Take this course for free
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.