How to Ignore a Return Value in Go with the Blank Identifier
Go refuses to compile a program with a local variable it never uses. When a function returns two values and you need only one, put the underscore, _, where the other would go: it accepts the value and throws it away.
Syntax
_, <keep> := <function>()
| Part | What it does |
|---|---|
_ | The blank identifier: takes a value and discards it. |
<keep> | A normal variable for the value you need. |
The Go specification: "The blank identifier is represented by the underscore character _. It serves as an anonymous placeholder instead of a regular (non-blank) identifier".
The Example
The example has a minMax function that returns the smaller and the larger of two numbers, and keeps only the larger.
Prerequisites
- Go.
go runcompiles and runs a single file. This guide uses Go 1.27.4.
Step 1: Write the Code
Create a file named main.go:

package main
import "fmt"
func minMax(a, b int) (int, int) {
if a < b {
return a, b
}
return b, a
}
func main() {
_, larger := minMax(8, 3)
fmt.Println(larger)
}
Step 2: Run It
go run main.go
8

The smaller number went into _ and was discarded. The command is the same in zsh, bash and PowerShell.
Why Not Just Name It?
Name the first value, smaller, larger := minMax(8, 3), without using smaller, and the program doesn't compile: Go reports declared and not used: smaller. The blank identifier says, on purpose, "I don't need this one".
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
| Naming a value you don't use | declared and not used: smaller | Replace it with _ |
Discarding an error with _ | Failures go unnoticed | Keep the error and check it |
Reading from _, as in fmt.Println(_) | cannot use _ as value or type | Use a named variable |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
declared and not used | A variable is assigned but never read | Use it, or assign to _ |
| A program silently uses zero values | An error was discarded with _ | Check the error instead |
FAQ
Where else is _ used?
In for _, item := range items to skip the index, and in import _ "package" to import a package only for its side effects.
Can I use _ several times in one assignment?
Yes. Each _ discards its own value, as in _, _, c := three().
Conclusion
Assign values you don't need to _ and Go discards them without complaining about unused variables. Use it for values that really don't matter, never to hide an error.
Additional Resources
- The blank identifier, in the Go specification.
- Effective Go: the blank identifier.
