<分区>
我在处理以下逻辑时遇到了问题:
假设我有一个列表 L = ['a', 'b', 'c']
两项都在列表中...
if ('a' or 'b') in L:
print 'it\'s there!'
else:
print 'No sorry'
打印它就在那里!
列表中只有第一项...
if ('a' or 'd') in L:
print 'it\'s there!'
else:
print 'No sorry'
打印它就在那里!
列表中的任何一项...
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... 中拍额头的简单答案