3 ms·
I like to think of it like this: For 0 based indexing the punctuation is the indexes/offsets: [ a , b , c ] 0 1 2
by zepolen 10y ago
I like to think of it like this:
For 0 based indexing the punctuation is the indexes/offsets:
[ a , b , c ]
0 1 2 3
for 1 based indexing consider the actual elements are the indexes/positions:
[ a , b , c ]
1 2 3
In the first case it is non inclusive, ie.
elements[0:3] - all items between offset 0 and 3
The second case is inclusive, ie.
elements[1:3] - all items including 1 and 3
Personally I don't have an issue with either, they both 'make sense'
Where they stop making sense is when you'd mix up the inclusivity ie (for the second case).
elements[1:4] - including item 1 not including 4