How do you get the logical xor of two variables in Python? by Tarik If you’re already normalizing the inputs to booleans, then != is xor. bool(a) != bool(b)