day04_02逻辑运算符

结果为布尔值(显式的、隐式的都算)的都可以当条件用

0代表False
非0代表True
True默认是1

not:把紧跟其后的条件取反
not 5 #结果False

and:同真则真,有一个为假就是假
5 > 4 and 4 > 6
结果为 False
5 and 6
结果 6
x and y
如果x为真,则返回 y,不管y的真假
x为假,则返回x,
不管y的真假

or:有真则真

5 > 4 or 4 >6
结果 True
5 or 4
结果 5
x or y
x为真,则返回真,不管y真假
x为假,则返回y,不管y真假
print(3>4 and 4>3 or not 1==3 and 'x' == 'x' or 3 >3 and not 'egon' != "egon" or 1 > 0)
(
3>4 and 4>3) or (not 1==3 and 'x' == 'x') or (3 >3 and not 'egon' != "egon") or 1 > 0 3>4 and (4>3 or not 1==3) and 'x' == 'x' or 3 >3 and not ('egon' != "egon" or 1 > 0)

先找紧跟not后的条件,然后在找and两边的条件,用添加在()中,然后就只剩下or

原文地址:https://www.cnblogs.com/HuaR-/p/14545093.html