Skip to content
This repository has been archived by the owner on Oct 4, 2022. It is now read-only.

Latest commit

 

History

History
26 lines (20 loc) · 920 Bytes

2014-10-22-zero-based-indexing.md

File metadata and controls

26 lines (20 loc) · 920 Bytes
layout title date categories slug
post
Zero based indexing
2014-10-22 10:00
python
zero-based-indexing

Reads

Comment

For Europeans zero based indexing feels reasonable if we think of floors in a house, the lowest floor is ground floor, then 1st floor and so on.

A house with 2 stories has ground and 1st floor. It is natural in this way to index zero-based and to count 1-based.

What about slicing instead? This is a separate issue from indexing. The main problem here is that if you include the upper bound then you cannot express the empty slice. Also it is elegant to print the first n elements as a[:n]. Slicing a[i:j] excludes the upper bound, so it probably easier to understand if we express it as a[i:i+n].