总结Python中逻辑运算符的使用
作者:goldensun 时间:2023-01-10 14:54:40
下表列出了所有Python语言支持的逻辑运算符。假设变量a持有10和变量b持有20,则:
示例:
试试下面的例子就明白了所有的Python编程语言提供了逻辑运算符:
#!/usr/bin/python
a = 10
b = 20
c = 0
if ( a and b ):
print "Line 1 - a and b are true"
else:
print "Line 1 - Either a is not true or b is not true"
if ( a or b ):
print "Line 2 - Either a is true or b is true or both are true"
else:
print "Line 2 - Neither a is true nor b is true"
a = 0
if ( a and b ):
print "Line 3 - a and b are true"
else:
print "Line 3 - Either a is not true or b is not true"
if ( a or b ):
print "Line 4 - Either a is true or b is true or both are true"
else:
print "Line 4 - Neither a is true nor b is true"
if not( a and b ):
print "Line 5 - Either a is not true or b is not true"
else:
print "Line 5 - a and b are true"
当执行上面的程序它会产生以下结果:
Line 1 - a and b are true
Line 2 - Either a is true or b is true or both are true
Line 3 - Either a is not true or b is not true
Line 4 - Either a is true or b is true or both are true
Line 5 - Either a is not true or b is not true
标签:Python
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
JS使用eval()动态创建变量的方法
2024-04-19 09:59:37
详解Python3中yield生成器的用法
2021-09-03 05:59:27
sqlserver数据库最大Id冲突问题解决方法之一
2024-01-28 01:48:06
Golang实现带优先级的select
2024-04-26 17:36:41
![](https://img.aspxhome.com/file/2023/5/133935_0s.png)
python使用rpc框架gRPC的方法
2021-02-28 06:28:37
python实现处理Excel表格超详细系列
2021-06-22 13:34:36
![](https://img.aspxhome.com/file/2023/5/105245_0s.png)
asp如何在约定时间显示特定的提示信息?
2010-06-28 16:52:00
ASP模拟POST提交数据的方法
2010-01-14 20:06:00
matplotlib 使用 plt.savefig() 输出图片去除旁边的空白区域
2023-06-24 02:55:42
JavaScript日期工具类DateUtils定义与用法示例
2024-04-16 08:51:29
![](https://img.aspxhome.com/file/2023/3/136833_0s.png)
vue中v-model指令与.sync修饰符的区别详解
2024-05-28 15:46:10
![](https://img.aspxhome.com/file/2023/4/123194_0s.jpg)
Python正则表达式实现截取成对括号的方法
2023-08-22 23:01:47
Mysql数据库的完全备份
2011-08-05 18:46:25
xorm根据数据库生成go model文件的操作
2024-01-16 00:29:22
ASP使用xmlhttp定时触发事件
2008-08-19 18:09:00
pandas数值计算与排序方法
2022-11-10 07:25:02
haskell实现多线程服务器实例代码
2021-08-06 00:08:22
django之导入并执行自定义的函数模块图解
2023-07-27 02:45:19
![](https://img.aspxhome.com/file/2023/0/86240_0s.jpg)
mysql索引对排序的影响实例分析
2024-01-18 16:52:29
![](https://img.aspxhome.com/file/2023/1/114001_0s.jpg)
SQL--JOIN之完全用法
2008-09-12 17:30:00