eof

Grant Edwards grante at visi.com
Mon Nov 26 11:00:22 EST 2007


On 2007-11-26, Boris Borcic <bborcic at gmail.com> wrote:
> hdante at gmail.com wrote:
>> def xor(a, b):
>> 	return a and not b or b and not a
>
>
> >>> from operator import xor
> >>> help(xor)
> Help on built-in function xor in module operator:
>
> xor(...)
>      xor(a, b) -- Same as a ^ b.

Which isn't the same thing:

------------------------------testit.py------------------------------
import operator

def xor(a,b):
    return a and not b or b and not a

print xor(1,3), operator.xor(1,3)
------------------------------testit.py------------------------------

$ python testit.py
False 2

The user-defined xor is operates on "logical" boolean values.
The one in the operator module is a bitwise operator.

-- 
Grant Edwards                   grante             Yow! My haircut is totally
                                  at               traditional!
                               visi.com            



More information about the Python-list mailing list