# Python逻辑运算符优先级顺序示例如下:
# 1. not (最高优先级)
# 2. and
# 3. or (最低优先级)
# 示例代码:
a = True
b = False
c = True
# 示例1:not的优先级高于and
result1 = not a and b # 等价于 (not a) and b,结果为False
print("result1:", result1)
# 示例2:and的优先级高于or
result2 = a and b or c # 等价于 (a and b) or c,结果为True
print("result2:", result2)
# 示例3:使用括号改变优先级
result3 = a or b and c # 等价于 a or (b and c),结果为True
print("result3:", result3)
# 示例4:复杂表达式
result4 = not a or b and c # 等价于 (not a) or (b and c),结果为False
print("result4:", result4)
下一篇:python 矩阵转置
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站