I want to know if someone can help me to understand, what is the difference between these 2 modes. Both resolve an expression. But it gives different results. In different learning pages explain that “value op= expression” is shorter than “value = value op expression”.
var /= 3 * 2 is the same as var = var / (3 * 2), as when using /=, Python would divide the variable on the left, with the value on the right, which can be simplified to var = var / 6.
Meanwhile, in var = var / 3 * 2, since there are no brackets at all (otherwise Python would evaluate the value inside the bracket first, like normal mathematical operations), so Python would just evaluate from left to right. So var = var / 3 * 2 can be simplified to var = 2 * 2 (var = 6 and 6 / 3 = 2), which will then be simplified to var = 4.0 , as 2 multiplied by 2 is 4.
To summarise, /= divides the var on the left by the final value on the right, while var = var / 3 * 2 will be evaluated from left to right since there are no brackets. If you bracket 3 * 2 you will find that var = 1.0 now. Hope this was clear.