Assignment¶
| Operator | Example | Equal to |
|---|---|---|
| = | x = y | x = y |
| += | x += y | x = x + y |
| -= | x -= y | x = x - y |
| *= | x *= y | x = x * y |
| /= | x /= y | x = x / y |
| %= | x %= y | x = x % y |
Operator +=¶
The operator += sums the values of the variables x plus y and assigns them to the variable x
x = 10
y = 5
x += y
escribir(x) //The result will be 15Operator -=¶
The operator -= subtracts the values of the variables x minus y and assigns them to the variable x
x = 10
y = 5
x -= y
escribir(x) //The result will be 5Operator *=¶
The operator = multiplies the values of the variables x by y and assigns them to the variable x
x = 10
y = 5
x *= y
escribir(x) //The result will be 50Operator /=¶
The operator /= divides the values of the variables x by y and assigns them to the variable x
x = 10
y = 5
x /= y
escribir(x) //The result will be 2Operator %=¶
The operator %= returns the remainder (module) that divides the values of the variables x by y and assigns them to the variable x
x = 10
y = 5
x %= y
escribir(x) //The result will be 0