You’ll be able to
- Extract sub-sequences with
[start:stop:step]syntax - Reverse sequences with a negative step
- Use slices to insert, delete, and replace multiple items
- Understand the difference between shallow copies and references
Loading lesson…
Why this matters
Slicing shows up in every pandas DataFrame, NumPy array, and Django queryset. Negative indices and stride tricks like s[::-1] for reversal are staples of LeetCode problems and one-line interview answers.
Common pitfalls
- Off-by-one:
s[0:3]returns 3 chars, not 4. The end index is exclusive; internalize this before touching pandas. - Assuming slicing raises on out-of-range:
s[100:200]on a short string returns'', not an error. Silent bugs. - Confusing
s[-1](last item) withs[:-1](everything but last). Both are common but do opposite things.