Suppose that 'xor' returns the value that is true when only one value is true, and False otherwise. This definition of xor doesn't have the standard associative property, that is,
(a xor b) xor c will not necessarily equal a xor (b xor c) To see that this is the case, let a= 1, b= 2, and c= 3. (a xor b) xor c yields 3, while a xor (b xor c) yields 1. So, I'd prefer an xor operator that simply returns True or False. Phillip MRAB-2 wrote: > > > <snip> > > What values should 'xor' return? IMHO, if only one of the values is true > then it should return that value, otherwise it should return False. > > 1 xor 0 => 1 > 0 xor 2 => 2 > 1 xor 2 => False > 0 xor 0 => False > > This is because it's a Boolean operator, so it should fall back to > Boolean values when necessary, like 'not': > > not 0 => True > not 1 => False > > Also: > > x and y and z => (x and y) and z > x or y or z => (x or y) or z > > therefore: > > x xor y xor z => (x xor y) xor z > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/missing-%27xor%27-Boolean-operator-tp24485116p24543805.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list