Arithmetic, Comparison and Logical Operators
Operators are special symbols that perform specific mathematical, logical or relational computations on variables of different types. We cover these three types of operators in this section:
- Arithmetic Operators
- Logical Operators
- Comparison Operators
While we don’t cover all corner cases and permutations of types, we’d like to focus on a few operators that might be interesting in the network automation context.
Arithmetic Operators
These operators perform mathematical calculations with numeric values. The resulting value depends on the order and type of the operands.
They follow the standard mathematical logic implemented in most programming languages.
func main() {
// sum s == 42
s := 40 + 2
// difference d == 0.14
d := 3.14 - 3
// product p == 9.42
p := 3 * 3.14
// quotient q == 0
q := 3.0 / 5
// remainder r == 2
r := 5 % 3
}
Strings...