擅长:python、mysql、java
<p>您正在使用<code>in</code>检查<code>'potatoe'</code>是否在列表中,但这将检查列表中的特定项是否正好是<code>'potatoe'</code>。你知道吗</p>
<p>只需遍历列表,然后检查:</p>
<pre><code>def stringInList(str, lst):
for i in lst:
if str in i:
return True
return False
</code></pre>
<hr/>
<pre><code>>>> lst = ['potatoechips', 'icecream', 'donuts']
>>> stringInList('potatoe', lst)
True
>>> stringInList('rhubarb', lst)
False
>>>
</code></pre>