python自学第二天之逻辑运算符

针对逻辑运算的研究: ()>not>and>or

and 并且的含义左右两侧同时为真,结果才能是真

or 或者的含义,左右两端有一个是真,结果就是真,所有的条件是假,结果才是假

not 取反 非真即假,非假即真

x or y,
    当x是非零,返回x
    当x是零,返回y

and 和 or 相反

示例:

print(1 or 2) #1

print(1 or 0) #1

print(0 or 1) #1

print(0 or 2) #2

print(0 or 1 or 2 or 3) # 1

print(3 or 0 or 1or 0 or 2) #3

and 和or相反,不要去总结and,记住or

示例:

print(1 and 2) #2

print(0 and 2) #0

print(1 and 0) #0

print(0 and 1) #0

print(1 and 2 or 3) #2

print(1 or 2 and 3) #1

注:先算and 后算or

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值