+ 1
Why the index of list always start from '0' ?
3 Réponses
+ 3
That's a design decision made by the makers of Python so they'd know for sure but I will speculate.
The designers of Python probably wanted to make that similar to arrays in most programming languages such as c and c++ which were very popular before Python was introduced in the early 1990's.
Another benefit could be a small performance benefit to 0-based arrays. Calculating the memory address associated with a[x] breaks down to a + x * sizeof(a single element of a). If a was a 1-based array, the memory address could require an extra decrement of x like: a + (x - 1) * sizeof(a single element of a).
Java, JavaScript, c# and many other newer languages have zero-based arrays for the same reason.
Some languages like Delphi have 1-based arrays but this is less popular.
0
Thank you so much