【发布时间】:2014-07-12 06:39:02
【问题描述】:
>>> list1 = ['yes', 'yeah']
>>> list2 = ['no', 'nope']
>>> 'no' in list2
True
>>> 'no' in list1
False
>>> 'no' in (list1, list2)
False
>>> 'no' in (list1 and list2)
True
>>> 'yes' in (list1 and list2)
False #want this to be true
>>> 'yes' in (list1 or list2)
True
>>> 'no' in (list1 or list2)
False #want this to be true
>>>
如你所见,我无处可去。
如果 x 或 y 在任一列表中,我怎样才能使它返回 true?
【问题讨论】:
-
我认为将上面使用的所有右手参数输入 python 解释器以查看它们返回的内容对您非常有帮助。这可能有助于您理解为什么这些方法都不起作用。