1. 比较运算符
常见的比较运算符:
><>=<===!=在 Python 的常见基础用法中,比较运算符返回的是bool类型:
3>2# True5==4# False10!=8# True比较运算符 → 返回
bool
2. 逻辑运算符
Python 中常见的逻辑运算符有:
andornotnot
not的返回值是bool:
not5# Falsenot0# True
not→ 返回bool
and和or
and和or不一定返回bool,它们会返回参与运算的值。
5and10# 100and10# 05or10# 50or10# 10
and/or→ 返回参与运算的值,不一定是bool
总结
比较运算符 → bool not → bool and / or → 参与运算的值,不一定是 bool