We break down how slices work in Go through the expression
s
[
a
:
b
]: why it is a half-open interval
[
a
,
b
), which boundary rules are checked via
len and
cap, how to quickly predict the result
len/
cap, what shorthand forms exist (
s
[:
b
],
s
[
a
:],
s
[:]), and how to avoid classic off-by-one mistakes and
panic for no good reason.