0

How to use the logical XOR operator in Python?

a Code I am working on requires me to evaluate two variables. It is an "if" statement that runs if ONE of them is equal to "x"...but not both. if height == x {XOR} width == x: ~code goes here Please help

28th Aug 2018, 2:42 PM
Trigger
Trigger - avatar
5 Answers
+ 1
It must be a construction like this: if a==40 and b!= 40 or b==40 and a!=40: If you are sure that any of your two vatiables necessarily equals to desired number, you can use canonical logical xor in that way: if a ^ b: In this case the if-statement will run the code if two variables differ, but will NOT do the check of the value.
28th Aug 2018, 3:04 PM
strawdog
strawdog - avatar
+ 3
😇
28th Aug 2018, 6:05 PM
Anna
Anna - avatar
+ 2
if (height == 40 or width == 40) and height != width: ###
28th Aug 2018, 6:00 PM
Anna
Anna - avatar
+ 1
😐I should have gotten that😓 Thanks again Anna ur like a Guardian Angel👍👌
28th Aug 2018, 6:03 PM
Trigger
Trigger - avatar
0
thank you Strawdog
28th Aug 2018, 3:17 PM
Trigger
Trigger - avatar