First of all, I\'d like to clarify the question: it\'s about the slice() function, not slices of lists or strings like a[5:4:3]
.
The docs menti
a[x:y:z]
gives the same result as a[slice(x, y, z)]
. One of the advantages of a slice
object is that it can be stored and retrieved later as a single object instead of storing x
, y
and z
.
It is often used to let the user define their own slice that can later be applied on data, without the need of dealing with many different cases.