-1

if (cond1 and cond2) or (not cond1 and not cond2):

Is there a simpler way to write this in Python?

Dova
  • 310
  • 3
  • 19
  • 2
    You mean `if (cond1 = cond2)`? – Ken White Mar 09 '17 at 03:54
  • 1
    @KenWhite: that'd by a syntax error. ;-) – Martijn Pieters Mar 09 '17 at 03:56
  • You want the inverse of `xor`, (so `xand`?), which is `bool(cond1) == bool(cond2)`. See the duplicate (with `!=` inverted to `==`). You can drop the `bool()` calls if both `cond1` and `cond2` are themselves boolean results. – Martijn Pieters Mar 09 '17 at 03:58
  • @MartijnPieters: OK. The logic is correct; the question still asks about equality of both variables (both true or both false). Fill in the correct syntax for the language, whether that's `=`, `==`, `equals`, or something else. :-) – Ken White Mar 09 '17 at 04:00
  • @SamuelLiew: yes, which is nothing more than the inversion of XOR. So `bool(a) != bool(b)` (XOR) becomes `bool(a) == bool(b)`. I do cover that in my comment. – Martijn Pieters Mar 09 '17 at 04:09

1 Answers1

3

If cond1 and cond2 are booleans, there certainly is:

cond1 == cond2
Paul Panzer
  • 51,835
  • 3
  • 54
  • 99