1.9. Augmented Assignments#
An augmented assignment combines an operator with assignment to produce a concise, readable statement.
Execution steps:
Evaluate the expression on the right-hand side of the equals sign to produce a value.
Apply the operator to the left-hand operand and the evaluated value, then assign the result back to the left-hand side. For mutable objects (e.g., lists), the operation may modify the object in place rather than rebind the name.
1.9.1. Augmented assignment operators#
Symbol |
Example |
Result |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Notes:
/=
always produces a float result, even when both operands are integers.//=
follows floor-division semantics: it rounds toward negative infinity for negative numbers.%=
follows Python’s modulo rule: the remainder’s sign matches the divisor’s sign.