arrow_upward
Why in python the indice are not beggining by 1 ?
#1
Its something i never could understand why when you create a list the indice always by 0 and not by one ?



#2
Because Python is based on C, and in C, you're adding multiples of a pointer to a base address to get an offset; the first one is zero because you're already pointing at the first element.

char *x = "Hello, world!" // x is a pointer that points to the first character of the string
x[0] == *(x + 0) == "H"
x[1] == *(x + 1) == "e"

Other languages (like Fortran and MATLAB) use 1 as the first index because they view an array as a vector, in the mathematical sense. It's not tied to the representation in memory, but to the abstract concept of a vector. Vectors are defined as starting at 1, so these languages start at 1.



[+] 1 user Likes nezzay's post