Python 之优先级排序

【原题】

   

  print(1 > 2 and 3 or 4 and 3 < 2 or not 4 > 5)

 

【解题思路】

  
  序:比较运算符 > 逻辑运算符 > not > and > or
  step1: print(1 > 2 and 3 or 4 and 3 < 2 or true)    # not 4 > 5 为 True
  step2: print(false and 3 or 4 and false or true) # 1 > 2 为 False,3 < 2 为 False
  step3: print(false or false or true)
   * false and 3,因为false为假所以and不再运算直接返回False;
   * 4 and false,因为4为真,所以and运算符会继续运算后面的,and只要有一个为假,即结果为假,所以返回False
  step4: print(false or true) # false or false 为假
  step5: print(true) # false or true 为 True

【答案】

 
   返回 True



 
 
 
 

转载于:https://www.cnblogs.com/wujiaqing/p/11426368.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值