You are adding the result of:
prices[key] * stock[key]
to "total" each time the loop runs. If you just run:
total = prices[key] * stock[key]
you will replace the result of the last item with the current.
We know that total is equal to zero (because we haven't added anything yet), a value set outside of the loop. For the first loop, the total price is as follows:
total = 0 + 4 * 6
where 4 is the price for banana, and 6 is the stock of banana
So now, total is equal to 24. Now, for the second loop, the total price is as follows:
total = 24 + 2 * 0
where 24 is the previous total, 2 is the price of apples, and 0 is the number of apples in stock
The new total is 24. But, if you were just to say total = 2 * 0, the new total would be wrong, because it would be zero. We are not trying to replace the total with each loop, but add to it for a grand total of all items.
Therefore, we write:
total = total + prices[key] * stock[key]
or total+= prices[key] * stock[key] for short. Think of it as the current total = previously calculated total + (current item price * current item stock).
I hope that helps. Feel free to ask for further clarification.