Python 逻辑运算符

pythonserver side programmingprogramming更新于 2023/12/10 19:50:00

Python 语言支持以下逻辑运算符。假设变量 a 为 10,变量 b 为 20,则 −

Sr.No运算符 &描述示例
1and 逻辑与
如果两个操作数都为真,则条件为真。
(a and b) 为真。
2or 逻辑或
如果两个操作数中有任意一个非零,则条件为真。
(a or b) 为真。
3not 逻辑非
用于反转其操作数的逻辑状态。
not (a and b) 为假。

相关文章