slice expression
Writing s[low:high] to get a new slice that views part of an existing slice, array or string.
In more detail
items[:2] gives the first two elements and os.Args[1:] skips the program name. The new slice shares storage with the original, so changing an element through one shows through the other.
Example
args := os.Args[1:]Related terms
- slice — A flexible, growable view over a list of values of one type, written like []string, and Go's everyday list.
- os.Args — The slice of strings holding the words a Go program was started with, where os.Args[0] is the program itself.
Taught in
- Arrays, Slices, and Maps — Concurrent Systems Programming with Go