What is the logic behind programming languages 0-indexing?

590 views

As someone who primarily uses R, I don’t understand why Python indexes lists starting from 0. I’m very slow at simple mental calculations and doing something like subsetting an array in Python often takes me several extra seconds.

I think I read that it has something to do with memory, but thats so much less of a consideration for people who only use high level languages.

In: Technology

9 Answers

Anonymous 0 Comments

At a deeper level, you need to figure out where in memory each item is. When the application asks the OS for memory for a variable, it gets given some address X. You will have the first item in the list at memory address X, the second at memory address X + offset, the third at X + 2* offset, the fourth at X + 3* offset, and so on.

So when you want to get a specific item from the array, you need to tell it how many offsets to use. The first item is right at the start of the list, so it has 0 offsets.

You are viewing 1 out of 9 answers, click here to view all answers.