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.

22nd Sep 2019, 8:50 PM
rodwynnejones
rodwynnejones - avatar
5 Answers
+ 1
Thank you Diego, I just could not work it out.
23rd Sep 2019, 9:53 PM
rodwynnejones
rodwynnejones - avatar
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')
22nd Sep 2019, 9:05 PM
rodwynnejones
rodwynnejones - avatar
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/
22nd Sep 2019, 9:56 PM
Diego
Diego - avatar