pythond的逻辑运算符有三种:

1、and: 与,前后两个操作数必须是True才返回True;否则返回False

2、or: 或,只要两个操作数中有一个是True,就可以返回True;否则返回False

3、not: 非,只需要一个操作数,如果操作数为True,则返回False,如果操作数为False,则返回True。

# 直接对False求非运算,将返回True
print(not False)
# 5>3 返回True,20.0大于10,因此结果返回True
print(5 > 3 and 20.0 > 10)
# 4>=5 返回False, 'c'>'a' 返回True,求或后返回True
print(4 >= 5 or 'c' > 'a')

有些时候,程序需要使用多个逻辑运算符来组合复杂的逻辑

bookName = '疯狂Python'
price = 79
version = '正式版'
if bookName.endswith('Python') and (price < 50 or version == '正式版'):
    print('打算购买这本Python图书')
else:
    print('不购买')