or
: A or B
: returns A
if bool(A)
is True
, otherwise returns B
and
: A and B
: returns A
if bool(A)
is False
, otherwise returns B
To keep most of that way of thinking, my logical xor definintion would be:
def logical_xor(a, b):
if bool(a) == bool(b):
return False
else:
return a or b
That way it can return a
, b
, or False
:
>>> logical_xor('this', 'that')
False
>>> logical_xor('', '')
False
>>> logical_xor('this', '')
'this'
>>> logical_xor('', 'that')
'that'