Go comparison operators can compare two values and returns a boolean value.
The following table lists the Go comparison operators.
Operator | Name | Example | Result |
---|---|---|---|
== | Equal | x == y | True if x is equal to y |
!= | Not equal | x != y | True if x is not equal to y |
< | Less than | x < y | True if x is less than y |
<= | Less than or equal to | x <= y | True if x is less than or equal to y |
> | Greater than | x > y | True if x is greater than y |
>= | Greater than or equal to | x >= y | True if x is greater than or equal to y |
The following example shows how to use Go comparison operators:
package main /* w ww . jav a2s . co m*/ import "fmt" func main() { var x, y = 5, 2 fmt.Println(x == y) fmt.Println(x != y) fmt.Println(x < y) fmt.Println(x <= y) fmt.Println(x > y) fmt.Println(x >= y) }