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