首页 > 其他 > 详细

Boolean Operations -- and, or, not

时间:2019-02-10 13:30:29      阅读:170      评论:0      收藏:0      [点我收藏+]

技术分享图片

 


 

  • Boolean Operations -- and, or, not
    • 布尔运算操作,优先级按升序排序:
      • x or y                 如果x为假,那么y,否则x                         短路运算符,只有当参数x为False,才计算参数y
      • x and y              如果x为假,则x,否则y                             短路运算符,只有当参数x为True,才计算参数y
      • not x                 如果x为假,那么True,否则False             not的优先级低于非布尔运算符,如 not a == b,实际上是 not (a == b);因此 a == not b 语法错误

 

 

# 测试“not”与“==”的优先级
x = 1
y = 0

try:
    if x == not y:
        print("this priority is : x == (not y)")
except  SyntaxError as err:
    print(err)

 

Boolean Operations -- and, or, not

原文:https://www.cnblogs.com/ShuComputerProgram/p/10359106.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!