What Are Augmented Assignment Operators?
Augmented Assignment Operators are a shortcut to combine:
• an arithmetic or bitwise operation
• with assignment
Instead of writing:
x = x + 5
You can write:
x += 5
That’s an augmented assignment!
Common Augmented Assignment Operators
Operator Meaning Example Same as
+= Add and assign x += 2 x = x + 2
-= Subtract and assign x -= 2 x = x - 2
*= Multiply and assign x *= 2 x = x * 2
/= Divide and assign x /= 2 x = x / 2
//= Floor divide and assign x //= 2 x = x // 2
%= Modulus and assign x %= 2 x = x % 2
**= Power and assign x **= 2 x = x ** 2
&= Bitwise AND and assign x &= 2 x = x & 2
` =` Bitwise OR and assign `x
^= Bitwise XOR and assign x ^= 2 x = x ^ 2
>>= Bitwise right shift and assign x >>= 1 x = x >> 1
<<= Bitwise left shift and assign x <<= 1 x = x << 1
Simple Examples
+= Add and Assign
x = 10
x += 5 # x = x + 5
print(x) # Output: 15
-= Subtract and Assign
x = 20
x -= 4 # x = x - 4
print(x) # Output: 16
*= Multiply and Assign
x = 3
x *= 4 # x = x * 4
print(x) # Output: 12
/= Divide and Assign
x = 10
x /= 2 # x = x / 2
print(x) # Output: 5.0
**= Power and Assign
x = 2
x **= 3 # x = x ** 3
print(x) # Output: 8
Bitwise Example: &=
x = 6 # Binary: 110
x &= 3 # Binary of 3: 011 → 110 & 011 = 010 (2)
print(x) # Output: 2
Summary
Augmented assignment makes your code:
Shorter
Cleaner
Easier to understand