day03 Python 逻辑运算符例题

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

  

 

转载于:https://www.cnblogs.com/fanghongbo/p/9818512.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值