Python doc for built-in function slice
is (emphasis mine):
class slice(stop)
class slice(start, stop[, step])
Return a slice object representing the set of indices specified by
range(start, stop, step)
. Thestart
andstep
arguments default toNone
. Slice objects have read-only data attributesstart
,stop
andstep
which merely return the argument values (or their default). They have no other explicit functionality; however they are used by NumPy and other third party packages. Slice objects are also generated when extended indexing syntax is used. For example:a[start:stop:step]
ora[start:stop, i]
. Seeitertools.islice()
for an alternate version that returns an iterator.
What does a[start:stop, i]
mean?
I tried it out (in Python 3.6):
a = [1, 2, 3, 4, 5, 6]
a[1:3,1]
but got:
TypeError: list indices must be integers or slices, not tuple