On May 5, 2014, at 10:13 PM, meenu ravi <meenurav...@gmail.com> wrote:
> Likewise, the index of d, which is the last word in the word "Hello world" is > 10. > > So, the maximum index you can access in the word "Hello world" is 10. But > when you try to give the command, > > >>> greeting [len(greeting)] > > It is trying to access the character at the position "11", where the string > "Hello world" doesn't contain any value in the index "11" and the maximum > index is 10. So it throws the following error. I think this is where I am getting confused. I guess I don’t understand why/how it’s trying to access the character at the index 11? > > Traceback (most recent call last): > > File "<stdin>", line 1, in <module> > > IndexError: string index out of range > > So always the maximum index will be length - 1. So if you want to access the > last character of the string "Hello world", give the command: > > >>> greeting[len(greeting)-1] > > 'd' > > Hope this helps _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor