擅长:python、mysql、java
<p>如果只想减小行的大小,可以将条件括在括号中:</p>
<pre><code>if (find_num_3 is not None
and find_num_3 != i
and find_num_3 != j):
# ...
</code></pre>
<hr/>
<p>您可以将每个条件值存储在变量中,这很方便,因为它命名了条件并使最终条件易于理解:</p>
<pre><code>defined = find_num_3 is not None
not_i = find_num_3 != i
not_j = find_num_3 != j
if defined and not_i and not_j:
#...
</code></pre>
<p>或:</p>
<pre><code>if all(defined, not_i, not_j):
# ...
</code></pre>
<hr/>
<p>您还可以检查<code>find_num_3</code>是否在值列表中:</p>
<pre><code>if find_num_3 not in (None, i, j):
# ...
</code></pre>