> At first glance this looked like it should be a simple boolean "and", but > then I realized that when a and c are both unequal to None, the result would > also be True. This implies the logical approach would be exclusive-or (^).
Among booleans, "!=" is exclusive or and "==" is its negation. I don't see the point of complicating the formula to use ^. (related: <= is implication. Which is sad, because the arrow points the wrong way!) The issue here is that "== None" is being used instead of "is None", but I believe that's been covered. Your response doesn't include it, so maybe it's worth restating. -- Devin On Sun, Dec 25, 2011 at 6:45 PM, Larry Hudson <org...@yahoo.com> wrote: > On 12/24/2011 11:09 PM, GZ wrote: >> >> Hi, >> >> I run into a weird problem. I have a piece of code that looks like the >> following: >> >> f(...., a=None, c=None): >> assert (a==None)==(c==None) >> > <...> > > At first glance this looked like it should be a simple boolean "and", but > then I realized that when a and c are both unequal to None, the result would > also be True. This implies the logical approach would be exclusive-or (^). > Try this expression: > > not ((a==None) ^ (c==None)) > > OTOH, if what you really want is simply to check that both are None (my > first impression), then it's simply: > > (a==None) and (c==None) > > Most of the replies you're getting here seem unnecessarily complicated. > >> Thanks, >> gz > > > -=- Larry -=- > -- > http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list