a *= b not equivalent to a = a*b

Jussi Piitulainen jussi.piitulainen at helsinki.fi
Fri Aug 26 02:32:14 EDT 2016


mlz writes:

> I've been playing with the binomial function, and found that in the
> below code, rs *= x does not behave the same way as rs = rs * x. When
> I set FAIL to True, I get a different result.  Both results are below.
>
> I had read that the two were equivalent. What am I missing?

You don't really have rs * x on the right-hand side. You have (rs * x)/y
where rs * x is always divisible by y but x alone is not.

For the record, your actual statement was rs = rs * (n-(i-1))/i, and you
are using Python 2 where / denotes integer division.

Try 3 * 4/6 and 3 * (4/6).



More information about the Python-list mailing list