Why can't I xor strings?

Steven Bethard steven.bethard at gmail.com
Sat Oct 9 03:03:03 CEST 2004


Grant Edwards <grante <at> visi.com> writes:

> No, he wants to do an exclusive or of the boolean values of the
> strings.

I'm guessing the OP has already guessed this solution from the variety already 
provided, but the direct translation of this statement would be:

bool(x) ^ bool(y)

for example:

>>> bool("") ^ bool("a")
True
>>> bool("") ^ bool("")
False
>>> bool("a") ^ bool("a")
False
>>> bool("a") ^ bool("")
True


Steve







More information about the Python-list mailing list