slice
A flexible, growable view over a list of values of one type, written like []string, and Go's everyday list.
In more detail
append adds items, growing the storage underneath when needed, and len gives the count. items[1] reads one element and items[:2] makes a smaller view of the first two. A nil slice is empty and safe to append to, so you rarely need to create one first.
Example
items := []string{"api", "worker"}Related terms
- array — A sequence of same-sized slots stored one after another in a single block of memory, so any slot can be reached by its index directly.
- append — The built-in Go function that adds values to the end of a slice and returns the updated slice.
- len — The built-in Go function that returns how many items a string, slice, map, array or channel holds.
- slice expression — Writing s[low:high] to get a new slice that views part of an existing slice, array or string.
- range loop — A Go for loop with the range keyword that visits each element of a slice, map, string or channel in turn.
Taught in
- Variables, Typing, and Zero Values — Concurrent Systems Programming with Go
- Pointers and Memory — Concurrent Systems Programming with Go
- Arrays, Slices, and Maps — Concurrent Systems Programming with Go
- Panics and Recover — Concurrent Systems Programming with Go
- Writing Table Driven Tests — Concurrent Systems Programming with Go
- Goroutines and Concurrent Execution — Concurrent Systems Programming with Go
- Files and the os Package — Concurrent Systems Programming with Go
- Executing Concurrent Checks — Concurrent Systems Programming with Go