Assignment Operator#

Assignment operators are used to assign and update values to variables.

See definition:

Operation

Operator

Examples

Assignment Operator

=

var_a = 10

Multiplication Assignment

*=

var_a *= 3 # var_a = var_a * 3

Division Assignment

/=

var_a /= 2  # var_a = var_a / 2

Addition Assignment

+=

var_a += 5 # var_a = var_a + 5

Subtraction Assignment

-=

var_a -= 2 # var_a = var_a - 2

Remainder Assignment

%=

var_a %= 3  # var_a = var_a % 3

Exponent Assignment

**=

var_a **= 2 # var_a = var_a ** 2

Examples

# Define a variable "var_a" by assigning 10
var_a = 10
# assign the multiplication of var_a by 3
var_a *= 3
print(var_a)
30
# assign the division of var_a by 3
var_a /= 2
print(var_a)
15.0
# assign the subtraction of var_a by -5
var_a -= 5
print(var_a)
10.0
# assign the exponent of var_a by 2
var_a **= 2
print(var_a)
100.0