Python Assignment Operators
Satellite · Operators
Python Assignment Operators
Combine operations with assignment to write compact, expressive code.
Operator table
| Operator | Example | Equivalent |
|---|---|---|
+= | count += 1 | count = count + 1 |
-= | balance -= fee | balance = balance - fee |
*= | price *= 1.1 | price = price * 1.1 |
/= | ratio /= total | ratio = ratio / total |
//= | batch //= 10 | Floor division |
%= | index %= length | Modulo assignment |
**= | value **= 2 | Exponentiation |
&=, ` | =, ^=` | Bitwise updates |
Mutability considerations
For mutable objects, augmented assignment may modify in place:
items = [1, 2]
alias = items
items += [3]
# alias now [1, 2, 3]
Use .copy() or rebind if you need isolation.