Comparison Operators
To check how two values relate to each other, you use a comparison operator.
Note: A comparison always produces one of two answers: true or false.
Here the greater than operator (>) checks whether x (5) is bigger than y (3), and the program prints the answer:
Example
Prompt
Compare two variables using the greater than operator and print the result.
Output: Go program and captured output
main.go
package main
import ("fmt")
func main() {
var x = 5
var y = 3
fmt.Println(x > y)
}
All Comparison Operators
Go gives you six comparison operators:
==Equal to!=Not equal>Greater than<Less than>=Greater than or equal to<=Less than or equal to
The Go Conditions chapter shows how to put them to work in your programs.