首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何得到Python中两个变量的异或逻辑?

如何得到Python中两个变量的异或逻辑?

提问于 2017-12-13 14:10:13
回答 2关注 0查看 5.4K

如何得到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 ^ 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'

回答

和开发者交流更多问题细节吧,去 写回答
相关文章

相似问题

相关问答用户
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档