擅长:python、mysql、java
<p>只有在遇到<code>break</code>时才会跳过<code>else</code>的<code>for-loop</code>。因此,<code>for-else</code>语句<em>不适合</em>在列表中查找多个元素。你知道吗</p>
<p>相反,使用列表理解并根据结果相应地打印。你知道吗</p>
<pre><code>lst = [100, 2, 1, 3000]
less_than_five = [x for x in lst if x < 5]
if less_than_five:
print(*less_than_five)
else:
print('There are no elements in this list greater than 5.')
</code></pre>