如何得到Python中两个变量的逻辑异或?
例如,我有两个变量,我希望是字符串。我想测试它们中只有一个包含True值(不是None或空字符串):
str1 = raw_input("Enter string one:")str2 = raw_input("Enter string two:")if logical_xor(str1, str2): print "ok"else: print "bad"该^运营商似乎是按位,并在所有对象没有定义:
>>> 1 ^ 10>>> 2 ^ 13>>> "abc" ^ ""Traceback (most recent call last): File "<stdin>", line 1, in <module>TypeError: unsupported operand type(s) for ^: 'str' and 'str'相似问题