why the result of the following operation is always 0 in the Python REPL? (got the same results for C and Javascript)
>>> a = 0
>>> a *= 1 + 1
>>> a
0
Shouldn't the multiplication assignment be equivalent to a = a * 1 + 1 in the case above?
>>> a = 0
>>> a = a * 1 + 1
>>> a
1
because
a *= 1 + 1
is the same as
a = a *(1 + 1)
since a is 0 then the result is still 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With