逻辑运算
逻辑运算
在没有()的情况下not 优先级高于 and,and优先级高于or,
即优先级关系为( )>not>and>or,同一优先级从左往右计算。
# print(3>4 or 4<3 and 1==1)#f # print(1 < 2 and 3 < 4 or 1>2)#t # print(2 > 1 and 3 < 4 or 4 > 5 and 2 < 1)#t # print(1 > 2 and 3 < 4 or 4 > 5 and 2 > 1 or 9 < 8)#f # print(1 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6)#f # print(not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6)#f # (not 2>1 f)
非0转换成布尔值为T,0位F
print(bool(-2))#T
x or y, x为真,值就是x,x为假,值是y;
x and y, x为真,值是y, x为假,值是x。
#print(3 > 1 and 1) # # 6 or 2>1 # 3 or 2>1 # 0 or 5<4 # 5<4 or 3 # 2>1 or 6 # 3 and 2>1 # 0 and 4>1 # 2>1 and 3 # 3>1 and 0 print(0 or 0)
版权声明:本文为ccqc原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。