Boolean Operations -- and, or, not
Posted shucomputerprogram
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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)
以上是关于Boolean Operations -- and, or, not的主要内容,如果未能解决你的问题,请参考以下文章
Voting and Shuffling to Optimize Atomic Operations
expression and operations添加运算符