Why numbering should start at zero?

Please note:

This has nothing to do with networking in particular! Not if you look from only one perspective. If you look from totally different perspective, with Cisco ACI and all other SDN solutions, you will probably meet with Python programming language (because you will) and then, somewhere in beginning of Python exploration this is the first question that will cross your mind. Of course, if you think like me!

Althoughnot directly related to networking, the question bothered me for some time now and the answer is not only really logical when you read it but it is also given by a cool guy named prof.dr. Edsger W. Dijkstra

For almost every networking geek it will be enough to read through it.

Intro

After getting the CCIE I found the next thing I wanted to get my hands around. Python. As it seems, Cisco ACI fabric will be the next big thing in Cisco world. Other vendors all have something about SDN to offer these days. Most important part for us, networking engineers, is that they want us to give up the CLI and get us to use Python and REST calls to speak with our network equipment. Python was the logical next step.

After first few great lectures on Coursera by Dr.Chuck the question was born!

The Question

So my questions arose: “Why the hell in Python slices and range exclude the last item?”, “Why?”, “It’s not logical to me!”

The Answer

After going through some books while learning Python fundamentals I actually found the answer. I found the reference to the answer by going through the book “Fluent Python” by Luciano Ramalho currently in early release by O’Reilly. The example below is stolen from that book to.

Python’s convention of excluding the last item in ranges and slices works great with zero-based indexing which is also used in Python.

Here are some benefits of this convention:

It shows the length of a range or slice when only the stop position is given: my_list[:6] and range(6) both produce six items.

It computes the length of a slice or range when start and stop are given by simply subtract start from stop.

It splits a sequence in two parts at any index x, without overlapping: