<p>我不认为这是由于左侧或右侧,但更多的是如何和-或评估。你知道吗</p>
<p>首先,在python中,0等于False,1等于True,但是可以重新分配True和False,但是默认情况下,0==0或0==False都是True。你知道吗</p>
<p>这就是说,您现在可以查看and-or运算符条件是如何计算的。你知道吗</p>
<p>总结:
<em>和</em>操作符总是在寻找一个假(0)值,如果他在第一个求值的参数上找到它,那么他就停止,但是如果他找到真或1,他就必须求值第二个条件,看看它是不是假。因为虚假的东西总是虚假的。这个表可能会帮你,看我什么时候有0(假)答案总是0(假)</p>
<pre><code>*and* truth table
0 0 = 0
0 1 = 0
1 0 = 0
1 1 = 1
</code></pre>
<p><em>或</em>有点不同,但机制相同:
<em>或</em>会寻找他找到的第一个真的。因此,如果他首先发现False,他将计算第二个参数,如果他在第一个参数中发现True(1),那么他停止。
这里当你有一个1(真)答案总是1(真)</p>
<pre><code>*or* truth table
0 0 = 0
0 1 = 1
1 0 = 1
1 1 = 1
</code></pre>
<p>你可以看看其他运营商只是谷歌运营商真值表,你会有很多其他更详细的例子。你知道吗</p>
<p>例如:</p>
<pre><code>#FOR BOOLEANS
print(False and 0) #prints False because *and* only need one False
print(0 and False) #prints 0 , because 0 = False and *and* only need one False
print(False or '') #prints '' because *or* is looking for a 1(True) but here both are False so he print the last one
print('' or False) #prints False (same reason as the one above) and he print the last one.
print(1 or True) #prints 1 because it's *or* and he found a True(1)
print(True or 1) #prints True same reason as above 1 = True so...
print(True and 1) #prints 1 because *and* is looking for a False and the first condition is True so he need to check the second one
print(1 and True) #prints True same as above 1 = True so and check for second paramater.
</code></pre>