For example, I have two variables that I expect to be strings. I want to test that only one of them contains a True value (is not None or the empty string):

```str1 = raw_input("Enter string one:")
str2 = raw_input("Enter string two:")
if logical_xor(str1, str2):
print "ok"
else:

The ^ operator seems to be bitwise, and not defined on all objects:

```>>> 1 ^ 1
0
>>> 2 ^ 1
3
>>> "abc" ^ ""
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for ^: 'str' and 'str'``` Aug 10, 2018 in Python 1,581 views

## 1 answer to this question.

What i found is that you can use the definition of xor to compute it from other logical operations:

`(a and not b) or (not a and b)`

But this is a little too verbose for me, and isn't particularly clear at first glance. Another way to do it is:

`bool(a) ^ bool(b)`

The xor operator on two booleans is logical xor (unlike on ints, where it's bitwise). Which makes sense, since bool is just a subclass of int, but is implemented to only have the values 0 and 1. And logical xor is equivalent to bitwise xor when the domain is restricted to 0 and 1.

So the logical_xor function would be implemented like:

```def logical_xor(str1, str2):
return bool(str1) ^ bool(str2)```
`this might help ` answered Aug 10, 2018 by
• 57,510 points

## In NumPy how do I get the maximum of subsets? Python

You can use np.maximum.reduceat: >>> _, idx = np.unique(g, ...READ MORE

+1 vote

## how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

## how do i use the enumerate function inside a list?

can you give an example using a ...READ MORE

## Lowercase in Python

You can simply the built-in function in ...READ MORE