I am never going to complain about Python again

MRAB python at mrabarnett.plus.com
Thu Oct 10 12:10:11 EDT 2013


On 10/10/2013 16:57, Rotwang wrote:
> On 10/10/2013 16:51, Neil Cerutti wrote:
>> [...]
>>
>> Mixed arithmetic always promotes to the wider type (except in
>> the case of complex numbers (Ha!)).
>>
>> r == c is equivalent to r == abs(c), which returns the magintude
>> of the complex number.
>
> What?
>
>   >>> -1 == -1 + 0j
> True
>   >>> -1 == abs(-1 + 0j)
> False
>   >>> 1 == 0 + 1j
> False
>   >>> 1 == abs(0 + 1j)
> True
>
Indeed.

If r is real (float) and c is complex:

     r == c means r == c.real and c.imag == 0.0




More information about the Python-list mailing list