python关系运算符or、and注意点

时间:2019-01-02 22:48:20   收藏:0   阅读:175

or运算符

运算符从左至右依次运算当or前面是数字时分两种情况,当or前面是0时,返回true,当or前面是1-9时,返回前面的数字。

print(0 or 2 and 3 >1)
print(5 or 2 and 3 >1)

and运算符

当and前面是0时,返回0.当and前面是1-9数字时,前面默认为true,则需判断and后面是true或者是False

print(0 and 3<1)
print(1 and 3<1)

 

原文:https://www.cnblogs.com/yangleiitzl/p/10211574.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!