Incorrect! Don’t forget to include the spaces in the count. Try again.
15
Correct! The len function returns the number of characters in the string, including spaces.
10
Incorrect! This would be true if the len function only returned the number of different characters present, but it includes all characters, including spaces. Try again.
6
Incorrect! This is the length of the word "street", not the length of the string named street. Try again.
The reason for the IndexError is that there is no letter in “banana” with the index 6. Since we started counting at zero, the six letters are numbered 0 to 5. To get the last character, you have to subtract 1 from length:
Alternatively, you can use negative indices, which count backward from the end of the string. The expression fruit[-1] yields the last letter, fruit[-2] yields the second to last, and so on.