>>> 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位於多個列表中的任何一箇中,我該如何返回True?
我該如何使它返回true,如果x或y在任一列表中?
我認爲將上面使用的所有右側參數輸入到python解釋器中以查看它們返回的內容是非常有用的。這可能會幫助你理解爲什麼這些方法都不起作用。 – DaoWen