boolean xor
Rainer Deyke
root at rainerdeyke.com
Wed Jan 10 17:52:05 EST 2001
"Andrew Dalke" <dalke at acm.org> wrote in message
news:93i9ff$q4l$1 at slb0.atl.mindspring.net...
> The expression "not ( (a and b) or (not (a or b)) )"
> checks the truth value of a and b, which means it calls
> __nonzero__ or __len__ as unary methods of the object.
> The == is a binary operator which may call the __coerce,
> __cmp__ or __rcmp__ methods, so your version does something
> different than the original code.
You could, however, remove a redundant 'not' from the original:
def xor(a, b): return (a or b) and not (a and b)
--
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games - http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor
More information about the Python-list
mailing list