Account
Categories

Subtract AND Assign Operator


Definition:

The Subtract AND Assign Operator (-=) is used to subtract a value from a variable and store the result in the same variable.

It subtracts the value on the right side from the variable on the left side.

Syntax:

variable -= value

Example:

x = 15
x -= 5  # subtracts 5 from x
print(x)

Output:

Exercise

Use the Subtract AND Assign Operator to subtract the value of b from a where a = 12 and b = 4, then print the result using Python.