Python - Assignment Operators
Python has assignment operators to assign values to variables and update their values.
- = - Assignment Operator
- += - Addition Assignment Operator
- -= - Subtraction Assignment Operator
- *= - Multiplication Assignment Operator
- /= - Division Assignment Operator
- %= - Modulus Assignment Operator
- **= - Exponentiation Assignment Operator
- //= - Floor Division Assignment Operator
Example
x = 4
x += 8 # x = x + 12
x -= 2 # x = x - 2
x *= 4 # x = x * 4
x /= 2 # x = x / 2
print(x) # 20