3 ms·
Another way to look at it, in languages like Python that support slicing, is that the indices refer to the boundaries between the elements rather than the eleme
by quietbritishjim 5y ago
Another way to look at it, in languages like Python that support slicing, is that the indices refer to the boundaries between the elements rather than the elements themselves.
a b c d
0 1 2 3 4
From this 4 character string you can slice s[1:3] and get 'b', 'c'. s[i:j] will always have j - i characters (ignoring negative indices). s[i] is as if it were short for s[i:i+1] e.g. s[3] is s[3:4] and that gives you 'd'.
Admittedly C++ doesn't have slicing so this is less relevant, but I think it's still an interesting aspect to the discussion (without getting bogged down in ideology).
- germandiago 5y agoIt has with std::span