|
|
|
|
|
by ColinWright
5397 days ago
|
|
Dijkstra explains it pretty clearly - there are two main reasons. The first is so that the number of elements in the array/list/vector/collection is given by upper-lower. The second is so that successive intervals re-use the same number, the upper bound of one becoming the lower bound of the next. This is python we can have: L[:3], L[3:6], L[6:23], L[23:40], L[40:]
With the repeated numbers we know that all elements of L have been included. Further, we know that given: L[start:end]
... then (provided L had at least "end" elements to start with) the resulting length is end-start. If you included the end point then the length would be end-start+1 which is fertile ground for fence-post errors. |
|