Skip to main content
Comparison operators compare two operands and return a Boolean value: true or false. Equality operators (==, !=) require operands to be of comparable types (typically the same type or types that the language allows to be compared). Ordering operators (<, <=, >, >=) require ordered types such as numeric types and strings. Common comparisons include checking whether two strings match, if two numbers are equal, or if one number is greater than another.
A presentation slide titled "Comparison Operators" with bullet points explaining that they compare two operands to yield a Boolean, require same data types, and giving examples (string match, number equality, greater‑than). The slide has a dark background and a small KodeKloud logo in the top-right.
Not all types are comparable using == and !=. Types such as slices, maps, and functions cannot be compared with equality operators — attempting to do so results in a compile-time error. Structs and arrays are comparable only if all their fields/elements are comparable.
We have the following comparison operators: equal (==), not equal (!=), less than (<), less than or equal to (<=), greater than (>), and greater than or equal to (>=).
A dark-themed slide titled "Comparison Operators" showing six boxed symbols: ==, !=, <, <=, >, >=. Each symbol is labeled beneath as equal, not equal, less than, less than or equal to, greater than, and greater than or equal to.
When comparing values in Go, make sure both operands are of comparable types. Use explicit conversions when necessary (for example, converting between int types) and prefer clear, readable comparisons to avoid subtle bugs.
Operator reference
OperatorMeaningTypical Use Case
==equalCompare identical values or strings
!=not equalCheck inequality
<less thanOrder comparisons (numbers, strings)
<=less than or equal toOrder or boundary checks
>greater thanOrder comparisons
>=greater than or equal toOrder or boundary checks
Examples Equal (==) The equal operator returns true when the two values are equal.
package main

import "fmt"

func main() {
	var city string = "Kolkata"
	var city2 string = "Calcutta"
	fmt.Println(city == city2)
}
$ go run main.go
false
Not equal (!=) The not-equal operator returns true when the two values are not equal.
package main

import "fmt"

func main() {
	var city string = "Kolkata"
	var city2 string = "Calcutta"
	fmt.Println(city != city2)
}
$ go run main.go
true
Less than (<) The less-than operator returns true when the left operand is strictly less than the right operand.
package main

import "fmt"

func main() {
	var a, b int = 5, 10
	fmt.Println(a < b)
}
$ go run main.go
true
Less than or equal to (<=) This operator returns true when the left operand is less than or equal to the right operand.
package main

import "fmt"

func main() {
	var a, b int = 10, 10
	fmt.Println(a <= b)
}
$ go run main.go
true
Greater than (>) The greater-than operator returns true when the left operand is strictly greater than the right operand.
package main

import "fmt"

func main() {
	var a, b int = 20, 10
	fmt.Println(a > b)
}
$ go run main.go
true
Greater than or equal to (>=) This operator returns true when the left operand is greater than or equal to the right operand.
package main

import "fmt"

func main() {
	var a, b int = 20, 20
	fmt.Println(a >= b)
}
$ go run main.go
true
Links and References That’s it for this lesson.

Watch Video

Practice Lab