bool behavior in Python 3000?

Stargaming stargaming at gmail.com
Wed Jul 11 16:05:00 CEST 2007


Alan Isaac schrieb:
> Miles wrote:
> 
>> What boolean operation does '-' represent?
> 
> 
> Complementation.
> And as usual, a-b is to be interpreted as a+(-b).
> In which case the desired behavior is
> False-True = False+(-True)=False+False = False

I always thought, at least in a Python context, A-B would trigger 
A.__sub__(B), while A+(-B) triggers A.__add__(B.__neg__()). A better 
choice could be A+~B (A.__add__(B.__invert__())) because it's always 
unary (and IMO slightly more visible).

> In response to Stargaming, Steve is making
> a point about the incoherence of certain arguments,
> not proposing an implementation.

Why should it be incoherent? Bjoern is pointing out an important aspect 
of how Python handles binary algebra (correctly). In contrast, Steven 
tries to invert his argument. Following, I showed why Steven's proof is 
wrong because his implementation fails at some aspects where the current 
one works. So I cannot see how Bjoern's argument is either wrong or not 
relevant.



More information about the Python-list mailing list