+ 1
Why numbering starts from 0
I wonder, why is the numbering the elements in a list starts from 0, instead of 1?
5 Respuestas
+ 5
Because you're specifying an offset (index) from the first valid position*, not a count (quantity) of items.
* often in order to do something with an item at that offset,
+ 2
don't know
but there will be some reason.
+ 2
Because by default number system of computation start from 0 to 9 and their repetation to form bigger numericals
+ 2
It is due to memory address. C/C++ would have learned you that :p
Python are list (I will explain how they are really structure next) so the ID you use is the number of time you'll need to go to the next element starting from the first one.
List are a data structure that is made like that :
List :
| valueOfElement
| nextElement //let say it can be None
So if you have the list [1,2,3,5], in reality you have :
1->2->3->5
I tried to explain without speaking of memory but if it is still unclear I will gladly add memory explanations :)
+ 1
0 is a number and is the smallest, within the positive numbers: why shuoldn't you start from 0, when going through the positive numbers in ascending order?
edit: think of a marked ruler (credits to Kirk shafer)