Why can't I xor strings?

David Bolen db3l at fitlinxx.com
Sun Oct 10 00:11:04 CEST 2004


Grant Edwards <grante at visi.com> writes:

> On 2004-10-09, Jeremy Bowers <jerf at jerf.org> wrote:
> >
> >> Regardless of whether this is the best implementation for
> >> detecting if two strings are similar, I don't see why xor for
> >> strings shouldn't be supported. Am I missing something?
> >
> > The basic problem is that there is no obvious "xor on string" operation
> 
> Sure there is.  Strings have a boolean value, and the xor
> operation on boolean values is well-defined.

That's an operation, but I'm not sure that's the obvious one.  For my
part, if I saw "string1 ^ string2" I'd probably expect a byte by byte
xor with the result being a new string.

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 (it would be in the same vein as string
+ number interpreting the string as a number - that way lies Perl :-))

-- David



More information about the Python-list mailing list