【发布时间】:2014-02-16 03:58:22
【问题描述】:
我遇到以下逻辑问题:
假设我有一个列表L = ['a', 'b', 'c']
两个项目都在列表中...
if ('a' or 'b') in L:
print 'it\'s there!'
else:
print 'No sorry'
打印It's there!
列表中只有第一项...
if ('a' or 'd') in L:
print 'it\'s there!'
else:
print 'No sorry'
打印It's there!
列表中没有项目...
if ('e' or 'd') in L:
print 'it\'s there!'
else:
print 'No sorry'
打印No sorry
这是令人困惑的一个只有列表中的第二个项...
if ('e' or 'a') in L:
print 'it\'s there!'
else:
print 'No sorry'
打印No sorry
我不明白为什么这不是一个真实的陈述。这如何推广到带有 n 个条件的 or 语句?
3、2、1中拍脑门的简单答案...
【问题讨论】:
-
“==”和“in L”的行为似乎不同
-
我上面的评论好像不正确
标签: python