相关疑难解决方法(0)

你如何在Python中获得两个变量的逻辑xor?

你如何在Python中获得两个变量的逻辑xor

例如,我有两个我期望成为字符串的变量.我想测试只有其中一个包含True值(不是None或空字符串):

str1 = raw_input("Enter string one:")
str2 = raw_input("Enter string two:")
if logical_xor(str1, str2):
    print "ok"
else:
    print "bad"
Run Code Online (Sandbox Code Playgroud)

^运营商似乎是按位,并在所有对象没有定义:

>>> 1 ^ 1
0
>>> 2 ^ 1
3
>>> "abc" ^ ""
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for ^: 'str' and 'str'
Run Code Online (Sandbox Code Playgroud)

python logical-operators

597
推荐指数
21
解决办法
65万
查看次数

标签 统计

logical-operators ×1

python ×1