Comparison Operators

Comparison Operators in Go #

Comparison operators are used to compare two values.

Note: The return value of a comparison is either true or false.

Example: Greater Than #

package main
import ("fmt")

func main() {
  var x = 5
  var y = 3
  fmt.Println(x > y) // true because 5 is greater than 3
}

List of Comparison Operators #

OperatorNameExample
==Equal tox == y
!=Not equalx != y
>Greater thanx > y
<Less thanx < y
>=Greater than or equal tox >= y
<=Less than or equal tox <= y

You will learn more about comparison operators and how to use them in the Go Conditions chapter.