In the simple case you give, there's little difference. Augmented assignment is just considered easier to read because it's a common idiom and expresses a common operation concisely.
But there are situations where it can make a difference. If the place you're incrementing comes from a complex expression or one that has side effects, you don't want to repeat it.
a[call_expensive_function()] += 1
vs
a[call_expensive_function()] = a[call_expensive_function()] + 1
Also, it's possible for a type to implement +=
differently from +
. An example is lists:
l1 = [1, 2, 3]
l2 = l1
l1 = l1 + [4, 5]
print(l1) # prints [1, 2, 3, 4, 5]
print(l2) # prints [1, 2, 3]
l3 = [1, 2, 3]
l4 = l3
l3 += [4, 5]
print(l3) # prints [1, 2, 3, 4, 5]
print(l4) # prints [1, 2, 3, 4, 5]
Lists implement +=
by modifying the list in place (like the extend()
method), while +
creates a new list. As you can see from above, this has implications if you have multiple references to the same list.