擅长:python、mysql、java
<p>使用<code>all()</code>:</p>
<pre><code>if all(word in ChatCommand for word in ("quit", "now")):
</code></pre>
<p>如果要避免在<code>quite</code>内匹配<code>quit</code>,可以使用正则表达式:</p>
<pre><code>import re
if all(re.search(regex, ChatCommand) for regex in (r"\bquit\b", r"\bnow\b")):
</code></pre>
<p>因为<code>\b</code><a href="http://www.regular-expressions.info/wordboundaries.html" rel="nofollow">word boundary anchors</a>只在单词的开头和结尾匹配。你知道吗</p>