I need some help on Access by Index but dont tell me the answer i need you to explain it to me


#1

i need some help this what i got

"""
The string "PYTHON" has six characters,
numbered 0 to 5, as shown below:

+---+---+---+---+---+---+
| P | Y | T | H | O | N |
+---+---+---+---+---+---+
0 1 2 3 4 5

So if you wanted "Y", you could just type
"PYTHON"[1] (always start counting from 0!)
"""
fifth_letter = "Y"[4]

print fifth_letter

dont tell me the anwser but can you explain it to me


#2

you see this example "PYTHON"[1] ,
if we wanna access the second character in that string ( PYTHON) our code will be "PYTHON"[1] ( why our index is 1 not 2 , because we begin with 0 , so index 0 is the first character and so on .. )
this code "PYTHON"[1] will return Y as output , "PYTHON"[0] return P ...


#3

oh i got it thank you


#4

Thanks a lot azazaz
i had the same problem and it helped quite a lot.
i thought i had to put:
fifth_letter = "Y" [4]
not:
fifth_letter = "MONTY" [4]


#5

Hey, so u need the fifth letter of MONTY, then dont just write it yourseld as u did ie Y[4]. The array [ ] will do that for you.

fifth_letter = "MONTY"[4]


#6

I dont get it how is y fifth letter if we counted from zero
M=0 O=1 N=2 T=3 and Y=4
We dont have any fifth letter here Right!