Explain the meaning of +=



I was stuck in the beginning but I took a look at the solution here, I got my code working. I just need help about += symbole, what does it mean exactly ?

total = 0
for key in prices :
    total += prices[key]*stock[key]
print total


The symbol is called a compound operator. It is compound because it consists of two operators, addition (+) and assignment (=). The addition operation takes place first,

x += 5

In the above 5 is added to the present value of x. The assignment operation replaces the current value with the new value, Consider the statement that this supplants..

x = x + 5



This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.