Why can't I xor strings?
db3l at fitlinxx.com
Mon Oct 11 00:06:48 CEST 2004
Grant Edwards <grante at visi.com> writes:
> Only because Python lacks a logical xor operator, so you're
> used to thinking of ^ as a bitwise operator. What if you saw
> string1 xor string2?
> Wouldn't you expect it to be equivalent to
> (string1 and (not string2)) or ((not string1) and string2)
Yes, no problem. I was definitely working with the bitwise operator
which is what I thought the OP was originally desiring.
> > It doesn't feel natural to me to have my strings suddenly
> > interpreted as a new data type based on the operation at hand.
> > Logical operators work that way but not numerics
> I don't know what you mean by that. Nobody seems to have a
> problem with "and" "or" and "not" operators using the truth
> values of strings. What is there about "xor" that precludes it
> from behaving similarly?
I think we're just talking about different items. I was referring to
the bitwise (^) xor operator (numeric), but not to a logical xor
operator. I'd have no problem with a separate logical operator that
behaved like the other logical operators.
The fact that saying "xor" can imply either isn't helping :-)
More information about the Python-list