What is the logic behind programming languages 0-indexing?

591 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

Think of it like directions to get someplace. If you stood at the start of a long hallway, and after every doorway there’s a clear divider. Then to reach a specific room, just count the dividers getting there.

1. 1st room is just as you walk in
2. 2nd room is after the 1st divider
3. 3rd room is after the 2nd divider
4. 4th room, 3rd divider…
5. 5th room, 4th divider…
6. Room 6 = Hallway[after 5 dividers
7. Room 7 = Hallway[6]

For a more technical answer, [Wiki: Zero Based Numbering](https://en.wikipedia.org/wiki/Zero-based_numbering)

Which provides some context that this design provides some optimizations and advantages.

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