布尔运算常见操作
1 最简单
x = 1 > 2
print(x)
# False
y = 2 > 1
print(y)
# True
2 基本操作
x, y = True, False
print((x or y) == True)
# True
print((x and y) == False)
# True
print((not y) == True)
# True
3 运算优先级
运算优先级:not > and > or
x, y = True, False
print(x and not y)
# True
print(not x and y or x) # 注意含有 or
# True
if None or 0 or 0.0 or '' or [] or {} or set():
print("Dead code") #永远都不执行
大家在看
AI安装教程
AI本地安装教程
微软AI大模型通识教程
微软AI大模型通识教程
AI大模型入门教程
AI大模型入门教程
Python入门教程
Python入门教程
Python进阶教程
Python进阶教程
Python小例子200道练习题
Python小例子200道练习题
Python练手项目
Python练手项目
Python从零在线练习题
Python从零到一60题