These (+=, -=, *= and /=) are called augmented arithmetic assignments. They correspond to the following methods:
object.__iadd__(self, other)
object.__isub__(self, other)
object.__imul__(self, other)
object.__idiv__(self, other)
the i semantically means “in-place”, which means that they modify the object (or reference in the case of numerics) without having to additionally assign them:
while condition:
foo += bar
is equivalent to:
while condition:
foo = foo + bar
They are performing the operation and then assigning it into the variable:
a += b is the same as: a = a + b
a -= b is the same as: a = a – b
a *= b is the same as: a = a * b
a /= b is the same as: a = a / b
You can use them in a while loop in the same way you would use the extended forms:
i = 0
while i < 5:
print i
i += 1 # The same of i = i + 1