blank identifier
The underscore _ used in place of a variable name to throw away a value you do not need.
In more detail
Go reports unused variables as errors, so _ is how you ignore, for example, the index in for _, name := range names. Ignoring an error with _ is legal but usually hides a real failure.
Example
for _, name := range names {}Related terms
- multiple return values — A Go function returning more than one result at once, most often a useful value together with an error.
- 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
- Arrays, Slices, and Maps — Concurrent Systems Programming with Go