在python的学习中,我们知道了布尔这一特殊的数据类型,那么对于这个特殊的数据类型来说,也有相应的运算,即称之为布尔运算。
以上图中显示出来的即是Python布尔运算中所有的逻辑关系:
and:逻辑与,并且
a,b=1,2
print("-----------and 并且-------")
print(a==1 and b==2)
print(a!=1 and b==2)
print(a==1 and b<2)
or:逻辑或,或者
c,d=10,20
print('-------or 或者----------')
print(c==10 or d!=20)
print(c==10 or d==20)
print(c!=10 or d!=20)
not:对逻辑结果取反
m=True
n=False
print(not m)#not True -> False
print(not n)#not False -> True
in / not in:判断你要的序列是否在指定的序列中,如果是返回True,不是则返回False
print('--------in /not in------')
s='helloworld'
print('h' in s)#True
print('l' in s)#True
print('mm' not in s)#True
print('H' in s)#False