What is the logic behind programming languages 0-indexing?

586 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

Back before arrays, when you had a list of items in memory, you had to math to pull the right on out:

address of i = base address + i * size of item

The first item is at the base address, so you need i = 0 to access it. The [] syntax was essentially an shortcut for the address math.

This also has roots in mathematics, where the first item in a series is subscripted at 0.

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