Python—逻辑运算符
2022/3/19 17:27:57
本文主要是介绍Python—逻辑运算符,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
逻辑运算符:
当有多个条件比较的时候,就需要用到逻辑运算符。
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")
这篇关于Python—逻辑运算符的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-08有遇到过吗?同样的规则 Excel 中 比Python 结果大
- 2024-03-30开始python成长之路
- 2024-03-29python optparse
- 2024-03-29python map 函数
- 2024-03-20invalid format specifier python
- 2024-03-18pool.map python
- 2024-03-18threads in python
- 2024-03-14python Ai 应用开发基础训练,字符串,字典,文件
- 2024-03-13id3 algorithm python
- 2024-03-13sum array elements python