Operators
Arithmetic: + - * / %. Assignment shortcuts: += -= *= /= and ++ -- as statements. Comparison: == != < > <= >=. Logical: && || !. Integer division drops the fraction. Bitwise: & | ^ << >>.
Example
a, b := 17, 5
fmt.Println(a+b, a-b, a*b, a/b, a%b)
a += 3
fmt.Println(a)
fmt.Println(a > b && b > 0, a == b, !(a < b))
fmt.Println(6&3, 6|3, 6^3, 1<<4)
fmt.Println(7.0 / 2)Result
22 12 85 3 2 20 true false true 2 7 5 16 3.5
Exercise
Remainder operator.
fmt.Println(17 5)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.