python 逻辑运算
and or not
优先级,()> not > and > or
print(3>4 or 4<3 and 1==1) # F print(1 < 2 and 3 < 4 or 1>2) # T print(2 > 1 and 3 < 4 or 4 > 5 and 2 < 1) # T print(1 > 2 and 3 < 4 or 4 > 5 and 2 > 1 or 9 < 8) # F print(1 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6) # F print(not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6) # F
ps int ---->bool 非0的数字转换bool值为True,0转换为bool值为False
print(bool(2)) print(bool(-2)) print(bool(0)) #bool --->int print(int(True)) # 1 print(int(False)) # 0
x or y x为True 则返回x
print(1 or 2) # 1 print(3 or 2) # 3 print(0 or 2) # 2 print(0 or 100) # 100
x and y x True,则返回y
print(2 or 1 < 3)#2 print(3 > 1 or 2 and 4)#4
相关推荐
运算符用于执行程序代码运算,会针对一个以上操作数项目来进行运算。以上实例中 7、5 和 12 是操作数。关系运算符用于计算结果是否为 true 或者 false。逻辑运算符用于测定变量或值之间的逻辑。
ChaITSimpleLove 2020-06-25
坚持是一种品质 2020-06-10
fly00love 2020-05-12
chenpro 2020-04-22
zuihaobushi 2020-03-03
一只码畜 2020-02-21
fanhuasijin 2020-02-19
luckymaoyy 2020-02-18
Dimples 2020-02-17
PythonMaker 2020-01-07
千锋 2019-12-22
fanhuasijin 2019-12-19
柠檬班 2019-12-19
林大鹏 2019-12-06