slicing [a:b]
Takes a piece of the list/string.
Syntax
items[start:end:step]
Description
You take a subset with square brackets. Start is included, end is excluded. A negative index counts from the end, and the step specifies skipping.
Returns
New items/text (slice).
Example
Loading editor…
Expected output
Hex ary [0, 2, 4]
When to use?
Taking the first N characters, cutting off the last part, selecting a piece of a list.
Common mistakes
- ⚠️ The end index is not included: h[0:3] takes 0,1,2, but not 3.