跳转至

🔥AI副业赚钱星球

点击下面图片查看

郭震AI

布尔运算常见操作

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") #永远都不执行

大家在看

京ICP备20031037号-1 | AI之家 | AI资讯 | Python200 | 数据分析