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
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.
+ 3
đ
+ 2
if (height == 40 or width == 40) and height != width:
###
+ 1
đI should have gotten thatđ
Thanks again Anna ur like a Guardian Angelđđ
0
thank you Strawdog