# Access by Index

<Below this line, add a link to the exact exercise that you are stuck at.>
<In what way does your code behave incorrectly? Include ALL error messages.>
I have absolutely no idea what to do here. There is no sixth number in “MONTY” so i have no idea what the Fifth number is if i am supposed to count starting at zero. It tells me that it is “Y” but i still have no idea what to code.
<What do you expect to happen instead?>

```python

fifth_letter =

``<do not remove the three backticks above>``
1 Like

@zinfaren
To index something, it starts by 0.

``````//let's say we have this string
//      M       O     N     T       Y
//      |       |     |     |       |
//      0       1     2     3       4 (indexing)
//      1       2     3     4       5 (real)
``````
1 Like

Thank you. But i’m still a bit confused. If it told me to count starting from zero then how is “y” the fifth letter?

1 Like

@zinfaren
Y (lol) wouldn’t y be the fifth letter?

It is the 4th index, but we are talking letters here.

2 Likes

@zinfaren

There’s two lines which I’ve written the numbers. The first line

Is about indexing an element (which starts by 0, you already know)
The second line

Is about the real number. So “M” will be the first letter but it will be index as 0.
Same for “Y” will be fifth letter but will be index as 4.

1 Like

Y is the fifth letter when counting as normal, so you want the output to be Y. You get this by counting the index numbers of the letters. The first letter is index 0, the second letter is index 1, etc. Basically to find the 5th letter, you look at index number [5-1], or 4.

1 Like

fifth_letter = MONTY[4]

this is what I have:

c = “cats”[0]
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!)
n = “Ryan”[3]
fifth_letter = “MONTY”[4]

3 Likes

but I am getting the error message: ‘invalid syntax line 2’

line 2 is the following:“The string “PYTHON” has six characters,”

Not sure what to do here

1 Like

never mind i figured it out. and the correct answer is:

c = “cats”[0]
six_letter = “PYTHON”[5]

n = “Ryan”[3]
fifth_letter = “MONTY”[4]

1 Like

What I wonder is; what is the purpose of this? For instance: It is not really efficient to print the letter “n” by typing:
`print "Monty"[2]`

@textmaster59538

Well, you can use it to get access to an item of an array in an iteration… There’s many way doing it and helps us not repeating ourselves sometime (when the loops come in)

fifth_letter = “MONTY”[4]

Maybe it doesn’t have quotes. I don’t know.

Never mind sorry i didn’t realize you already figured it out.

that is what I have exactly, but it says i didn’t use the access operator , when I did

Code:
“”"
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 = “MONTY”[04]

print fifth_letter

The way that they worded the question is terrible. It’s just a terrible question.

2 Likes