Assignment Operators in Python
The = operator assigns a value to a name. Python also provides compound assignment operators that combine an operation with assignment in one step — += adds and reassigns, -= subtracts and reassigns, and the same pattern applies to every arithmetic operator. These aren't just shorthand; they make the intent "update this variable based on its own value" explicit.
Plain assignment
name = value binds a name to a value.
+= is shorthand
name += value means name = name + value.
The same pattern covers every operator
-=, *=, /=, //=, %=, and **= all follow the identical shorthand pattern.
Works on any supporting type
Including string concatenation with += , since + already works on strings.
Multiple variables in one line
a, b = 1, 2 assigns both at once, matching values to names in order.
score = 10score += 5print(score) message = "Hello"message += ", World!"print(message) a, b = 1, 2print(a, b)Compound Arithmetic (+=, -=, *=, /=)
Shorthand for "update this variable based on its current value," using any arithmetic operator.
total = 100total -= 25print(total)Multiple Assignment
Assign several variables at once on one line, or the same value to several names.
x = y = z = 0print(x, y, z)Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in Python yourself — building beats watching.