[Tutor] weird bool

Andre Engels andreengels at gmail.com
Tue Feb 3 11:50:57 CET 2009


On Tue, Feb 3, 2009 at 11:40 AM, prasad rao <prasadaraon50 at gmail.com> wrote:
> hi
>>>> a=2.1
>>>> a%1==True
> False
>>>> a%1==False
> False
>>>> b=3.8
>>>> b%1==True
> False
>>>> b%1==False
> False
> If it gives correct bool, it could be put to good use.

== gives a high degree of equality. In your idea, it would not be a
kind of equality at all, because you would have:

>>> 1 == True
True
>>> 2 == True
True
>>> 1 == 2
False

It would also be confusion as to when '==' would mean logical equality
and when real equality:

>>>> 1 == ((0 == 0) or not (0==0))
True
>>>> 1 == ((0 + 0) * (0 + 0))
False
>>>> True == 1
???

Finally, it is rarely necessary:
>>> a=2.1
>>> bool(a%1)==True
True

That's a few characters more, but to me that's more than compensated
by the gains in clarity and consistency (== is an equivalence
relationship, at least unless you have redefined it for your own class
in a less practical way)

--
André Engels, andreengels at gmail.com


More information about the Tutor mailing list