Index v.s. len()


Why does index start counting from 0 while len() from 1 ?
I understand len() counts all character in a string, including spaces, but I can’t figure out the reason behind index.

Please leave the following link in the post so we can find the unit module, else replace it with a link to the exact lesson:

Strings and Console Output


well, python is a very friendly language, so they probably made len() start at one, to make it easier for us (programmers). len() is a function build by a programmer, so it can be made friendly for other programmers to use

There could be historic reasons (legacy code) why indexes start at zero, maybe long ago this was easier to implement. If one language then implements this different today, that would be confusing, programming languages are tools to get a job done, so it would be really confusing if certain core principals of a language are different (indexes for example)

there could be many reasons why indexes are zero, i speculated on a few above, if you really want to know, you should google it. The question is, how interesting is to learn at this point? As you will explore other programming languages, you will see that indexing is zero.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.