Comparison and Logical Operators
Comparison operators are == != < > <= >=. Logical operators are && || !, and they short circuit. Arrays and structs are comparable, slices and maps are not.
Example
a, b := 5, 10
fmt.Println(a < b, a == b, a != b)
fmt.Println(a > 3 && b > 3, a > 7 || b > 7, !(a > 7))
type P struct{ X, Y int }
fmt.Println(P{1, 2} == P{1, 2}, [2]int{1, 2} == [2]int{1, 3})Result
true false true true true true true false
Exercise
Logical not.
(a > b)Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.