0
Exclusive Or
How do i implement an exclusive OR in python (and yes... i have done a search on here)? i.e. false false = false false true = true true false = true true true = false.
3 ответов
+ 1
Thank you Diego, I just could not work it out.
0
The '^' is a bitwise operator. As a simple example of what I mean;
a = 10
b = 10
if a == 10 XOR b == 10: # true if only one is true, but not both.
print('blah blah blah')
0
If you're only working with two operands you could use "!=".
a = 10
b = 10
# True if exactly one is True
if (a == 10) != (b == 10):
print(42)
If you're going to work with more than 2 operands take a look at this thread:
https://stackoverflow.com/questions/432842/