Skip to main content

Python Assignment Operators

Satellite · Operators

Python Assignment Operators

Combine operations with assignment to write compact, expressive code.

Operator table

OperatorExampleEquivalent
+=count += 1count = count + 1
-=balance -= feebalance = balance - fee
*=price *= 1.1price = price * 1.1
/=ratio /= totalratio = ratio / total
//=batch //= 10Floor division
%=index %= lengthModulo assignment
**=value **= 2Exponentiation
&=, `=, ^=`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.

Next up in your learning path