Python中OR和AND运算符有何不同?
在Python中,and和or(以及not)被定义为逻辑运算符。两者都需要两个操作数,其结果可能为true或false。
仅当两个操作数均为True时,and运算符才返回True。
>>> a=50 >>> b=25 >>> a>40 and b>40 False >>> a>100 and b<50 False >>> a==0 and b==0 False >>> a>0 and b>0 True
如果任一操作数为true,则or运算符返回True。
>>> a=50 >>> b=25 >>> a>40 or b>40 True >>> a>100 or b<50 True >>> a==0 or b==0 False >>> a>0 or b>0 True
热门推荐
10 简短祝福语大全暖心
11 38节贺卡简短祝福语
12 年前幸福祝福语大全简短
13 安徽疫情祝福语简短英语
14 近代生日祝福语简短精辟
15 打牌翻盘祝福语简短
16 发小结婚简短祝福语
17 迎接朋友蛋糕祝福语简短
18 生日祝福语 简短独特高考