When slicing in python, omitting the portion of the end slice (that is, the end in list[:end:] ), the end result is defined as "the size of the chopped string." *
However, this is not like using the step argument (step in list[::step] ) in the slice, at least when the argument step is -1 . A simple example:
>>> l = [1, 2, 3] >>> l[::-1] [3, 2, 1] >>> l[:len(l):-1] []
This means that in the case of the step argument passed, the value of the skipped end is not equivalent to the explicitly passed size of the sliced ββobject.
This may just be a failure of my reading the documentation, but I would like to understand why my previous example seems to contradict the Python documentation about excluding end values ββin slices and, ideally, where this document is documented.
*
Fragment indices have useful defaults; the omitted first index is zero by default; the omitted second index defaults to the size of the sliced ββrow.
python slice
Nolen Royalty
source share