- Simple assignment (=)
- Addition assignment (+=)
- Subtraction assignment (-=)
- Multiplication assignment (*=)
- Division assignment (/=)
- Modulus assignment (%=)
Simple Assignment Operator
The simple assignment operator (=) assigns the value from the right-hand side to the variable on the left-hand side. For example, writing x = y assigns the current value of y to x. Example:Addition Assignment Operator
The addition assignment operator (+=) adds the right-hand operand to the left-hand operand and updates the left-hand operand with the new value. In other words, x += y is equivalent to x = x + y. Example:Subtraction Assignment Operator
The subtraction assignment operator (-=) subtracts the right-hand operand from the left-hand operand and stores the result back in the left-hand operand. That is, x -= y is the same as x = x - y. Example:Multiplication Assignment Operator
The multiplication assignment operator (*=) multiplies the left-hand operand by the right-hand operand and assigns the product to the left-hand operand. This operation is equivalent to x = x * y. Example:Division Assignment Operator
The division assignment operator (/=) divides the left-hand operand by the right-hand operand and updates the left-hand operand with the quotient. Essentially, x /= y means x = x / y. Example:Modulus Assignment Operator
The modulus assignment operator (%=) divides the left-hand operand by the right-hand operand and assigns the remainder back to the left-hand operand. In other words, x %= y divides x by y and stores the remainder in x. Example:Practice these assignment operators with your own examples to deepen your understanding of Golang’s efficient coding practices.