<blockquote>
<p><strong>Possible Duplicate:</strong><br/>
<a href="https://stackoverflow.com/questions/3931541/python-check-if-all-of-the-following-items-is-in-a-list">Python Check if all of the following items is in a list</a> </p>
</blockquote>
<p>所以我想测试word和word1是否都在列表lst中。
当然,我可以写:</p>
<pre><code>if word in lst and word1 in lst:
do x
</code></pre>
<p>但我想知道我是否可以把这句话缩短为:</p>
<pre><code>if (word and word1) in lst:
do x
</code></pre>
<p>当然,这是行不通的,但有没有什么有效的相似之处呢?</p>
<p>我尝试了下面的方法,但正如你所见,它并没有产生预期的结果。</p>
<pre><code>>>> word in lst
True
>>> word1 in lst
True
>>> (word, word1) in lst
False
</code></pre>
<p><strong>编辑:</strong>谢谢您的回答,我想我现在已经很清楚该怎么做了。</p>