4. Access by Index


#1

On line 13, assign the variable fifth_letter equal to the fifth letter of the string "MONTY".


#2

print fifth letter equal to "Y" latter of monty

put

a = "MONTY"
fifth_letter = a[4]


#3

It wants you to print the 5th letter, so just put
fifth_letter="MONTY"[4]


#4

Thank you, this totally works, However, i dont understand why. It says python starts counting from 0 and the string "MONTY" is 0,1,2,3,4 characters long, so how is printing the fifth letter even possible? This is my first language btw, so please, if anyone can explain this to me in plain english that would be awesome Oh! wait! i get it.. i think.. so MONTY is 5 characters long, and Y is the 4th letter in the string right? so assigning the variable, fifth_letter =x, to print the 5th letter you need to tell it to print the fourth count in from the beginning?!


#5

Hello,

string starts a 0th index eg

1st Letter 2 nd letter
M O
0th Index 1st Index

and so on ......

lets say you have a var

var1 = 'Hello World!'
to access "H" in hello world you have to print it like shown below

print "var1[0]: ", var1[0]

because first letter is at 0th index


#6

The answer is

fifth_letter = "MONTY"[4]