Boolean Operations -- and, or, not


  • 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)
原文地址:https://www.cnblogs.com/ShuComputerProgram/p/10359106.html