逻辑运算符:
当有多个条件比较的时候,就需要用到逻辑运算符。
Python 语言支持逻辑运算符:
and 代码示例:
color = input('你白吗?') rich = int(input('请输入你的资产 0 - 999999999....')) beautiful = input('你美吗?') # and是必须同时满足 if color == '白' and rich > 100000000 and beautiful == '美': print('你是一个白富美,嫁给我吧!') else: print('你是个好人')
or 代码示例:
color = input('你白吗?') rich = int(input('请输入你的资产 0 - 999999999....')) beautiful = input('你美吗?') # or 是必须满足一个 if color == '美' or rich > 10000000: print('亲爱的,爱老虎油') else: print('你是个好人')
not 代码示例:
has_girlfriend = False # not 是对后面的结果取得一个相反的结果 if not has_girlfriend: print("你是一个单身狗!")
注意:1、非 0的数字都是 True
2、空""字符串都是 True
flag = True # not就是取相反的值 if not flag: print("kakakak") else: print("lalalal")