[Tutor] toggle idiom?

Erik Price erikprice@mac.com
Thu, 9 May 2002 07:50:37 -0400


On Thursday, May 9, 2002, at 12:12  AM, dman wrote:

> Old code would only break when it uses the boolean values in a
> non-boolean context or when checking equality of two "boolean" values.
> For example the following snippets :
>
> if a and b : print "good"
> if a == b : print "not good"
>
> The former will not break as long as the truth value of the objects
> remains the same (which is independent from "True==1").  It can even
> handle the situation where different "true" values are used for a and
> b.  The second expression would break if a and b were different
> objects both evaluating to true.

Won't the former also print "good" if for some reason the value of a is 
1 and the value of b is 2?

This could be problematic too, no?  Or do we just have to trust that 
this test is ONLY being used for boolean value, and that we aren't 
checking for isequals or any other value test....




Erik