On this page
  1. slice
  2. Import & Availability
  3. Overview & Signature
  4. Common Methods & Attributes
  5. Usage
  6. Gotchas
  7. REPL Inspect

slice

Prev: setattr | Up: __builtins__ | Next: sorted
Rel: bool, int, float, complex, str
Ref: docs.python.org — slice
Tags: #public #python3 #builtins


Import & Availability

# Built-in (available globally without import)
from builtins import slice

Overview & Signature

slice(stop)

slice(start, stop[, step]) Create a slice object.

Common Methods & Attributes

Usage

last_two = slice(-2, None)
assert [10, 20, 30, 40][last_two] == [30, 40]
assert slice(0, 10, 2).indices(5) == (0, 5, 2)

Gotchas

REPL Inspect

help(slice)

Linked from

Related notes