When I was looking at meaning of the += operator in Python, I looked at the answers to a similar question: What exactly does += do in python?. But in the below code excerpt:
increments += arr[i-1] - arr[i]
There is a third variable used. If I understood the concept it subtracts arr[i]
from arr[i-1]
and adds it to increments
's value and the result is assigned to increments
. To elaborate: is the above statement similar to
increments = increments + (arr[i-1] - arr[i])
or is there more to it?
From the documentation:
(my emphasis in the second paragraph)
So yes, there's more to it than just
increments = increments + (arr[i-1] - arr[i])
. The degree to which it matters depends on what you're applying the operator to.