We're back after a server migration that caused effbot.org to fall over a bit harder than expected. Expect some glitches.

Slice Objects

Slice objects are used to represent slices when extended slice syntax is used. This is a slice using two colons, or multiple slices or ellipses separated by commas, e.g., a[i:j:step], a[i:j, k:l], or a[..., i:j]. They are also created by the built-in slice function.

Special read-only attributes:

  • start is the lower bound
  • stop is the upper bound
  • step is the step value

Each is of the above is None if omitted.

These attributes can have any type.

Slice objects support one method:

indices(self, length)

This method takes a single integer argument length and computes information about the extended slice that the slice object would describe if applied to a sequence of length items. It returns a tuple of three integers; respectively these are the start and stop indices and the step or stride length of the slice. Missing or out-of-bounds indices are handled in a manner consistent with regular slices. New in version 2.3.