擅长:python、mysql、java
<p>该<code>print string</code>行独立于if语句。也就是说,不管你的条件是否正确,它都会被执行。你知道吗</p>
<p>您需要一个<code>else:</code>块来执行您想要的操作:</p>
<pre><code>string = line.split(',')
if string[0] != 'Aa' and string[0] != 'Bb': # You need 'and' up here
pass
else:
print string # This will only be executed if the condition is false
</code></pre>
<p>但这有点多余。更好的方法是:</p>
<pre><code>string = line.split(',')
if string[0] == 'Aa' or string[0] == 'Bb':
print string
</code></pre>
<p>或者:</p>
<pre><code>string = line.split(',')
if string[0] in {'Aa', 'Bb'}:
print string
</code></pre>