Comparisons of incompatible types

Carl Banks pavlovevidence at gmail.com
Tue Dec 7 18:31:53 EST 2010


On Dec 7, 3:08 pm, John Nagle <na... at animats.com> wrote:
> The basic Boolean identities
>
>         (a or b) == (b or a)
>         not (a or b) == (not a) and (not b)
>         not (not a) == a
>
> should all hold, or an type exception should be raised.
> With Python accepting both "True" and "1" as sort of
> equivalent, there are cases where those don't hold.

For better or worse (and I say worse, but YMMV) "and" and "or" are not
boolean operators in Python but special-form expressions that resemble
boolean semantics in some instances, but not (as you mention above) in
others.

Likewise, the comparison operators <, >, >=, and <= aren't well-
ordered; sets use these operators to indicate topological ordering.

IMO having the operators adhere to defined properties would be a good
thing.  It would improve code reusability since the operators could be
expected to act in consistent ways, but Python isn't that language.
So you might as well use the operators for whatever seems like it
works, + for concatenation, > for superset, and so on.


Carl Banks



More information about the Python-list mailing list