Learn
Variables
Mathematical Assignment Operators are used to perform arithmetic operations and assign the result back to the same variable.
The most common Mathematical Assignment Operators are:
Addition Assignment Operator +=
It adds the value on the right-hand side to the value on the left-hand side and assigns the result back to the variable.
Example:
Subtraction Assignment Operator -=
It subtracts the value on the right-hand side from the value on the left-hand side and assigns the result back to the variable.
Example:
*Multiplication Assignment Operator: =
The multiplication assignment operator *=
multiplies the value on the right-hand side with the value on the left-hand side and assigns the result back to the variable.
Example:
By using these mathematical assignment operators, we can perform arithmetic operations in a concise and efficient manner while assigning the result back to the variable.
Declare a new variable sum
and assign it the value of x
plus y
.
Print the value of sum
.
Declare a new variable quotient
and assign it the value of x
divided by y
.
Print the value of quotient
.
Sign up to start coding
Already have an account?
Sign In