How do you get the logical xor of two variables in Python?

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'```
May 29, 2018 in Python 10,534 views

## 1 answer to this question.

If you're already normalizing the inputs to booleans, then != is xor.

`bool(a) != bool(b)`
answered May 29, 2018 by
• 7,450 points

## How do you get the logical xor of two variables in Python?

What i found is that you can use ...READ MORE

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

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

## How do you get a list of all the keys in a dictionary?

Hey, @Roshin, I would like to give you ...READ MORE

## How can I compare the content of two files in Python?

Assuming that your file unique.txt just contains ...READ MORE

## How can I get the count of a list in Python?

n=[1,2,3,4,5,6,7,8,9] print(len(n)) =9 READ MORE

## How do I obtain the index list in a NumPy Array of all the NaN values present using Python?

Hi, it is pretty simple, to be ...READ MORE

+1 vote

## How do I find out the sum of digits of a number in Python?

Hi, good question. If you are considering ...READ MORE

## how do I check the length of an array in a python program?

lets say we have a list mylist = ...READ MORE