1、逻辑运算符
- or : x or y , x为真,值就是x,x为假,值是y。if x is false then y else x
- and : x and y, x为真,值是y,x为假,值是x。if x is false then x else y
- not : x 为真,not x 为假。if x is false then true else false
注:在没有()的情况下not 优先级⾼高于 and,and优先级⾼高于or,即优先级关系为( )>not>and>or,同⼀一优先级从左往 右计算。
() > not > and > or
2、例题
1、判断下列列逻辑语句句的True,False. 1 > 1 or 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6 True not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6 False 2、求出下列列逻辑语句句的值。 1),8 or 3 and 4 or 2 and 0 or 9 and 7 8 2),0 or 2 and 3 and 4 or 6 and 0 or 3 4 3、下列列结果是什什么? 1)、6 or 2 > 1 6 2)、3 or 2 > 1 3 3)、0 or 5 < 4 False 4)、5 < 4 or 3 3 5)、2 > 1 or 6 True 6)、3 and 2 > 1 True 7)、0 and 3 > 1 0 8)、2 > 1 and 3 3 9)、3 > 1 and 0 0 10)、3 > 1 and 2 or 2 < 3 and 3 and 4 or 3 > 2 2