• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > 总结Python中逻辑运算符的使用

总结Python中逻辑运算符的使用

作者:goldensun 字体:[增加 减小] 来源:互联网

goldensun 通过本文主要向大家介绍了python中逻辑运算符,python逻辑运算符,逻辑运算符,c语言逻辑运算符,java逻辑运算符等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

下表列出了所有Python语言支持的逻辑运算符。假设变量a持有10和变量b持有20,则:

2015513121854474.jpg (586×254)

 示例:

试试下面的例子就明白了所有的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"

</div>

当执行上面的程序它会产生以下结果:

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

</div>

</div>

您可能想查找下面的文章:

  • 总结Python中逻辑运算符的使用

相关文章

  • Python聚类算法之基本K均值实例详解
  • 使用tensorflow DataSet实现高效加载变长文本输入
  • python遍历数组的方法小结
  • Python内置函数bin() oct()等实现进制转换
  • python获取文件版本信息、公司名和产品名的方法
  • Python中使用bidict模块双向字典结构的奇技淫巧
  • 深入源码解析Python中的对象与类型
  • windows下python模拟鼠标点击和键盘输示例
  • python基础教程之基本内置数据类型介绍
  • 在Python中用get()方法获取字典键值的教程

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • 用python实现批量重命名文件的代码
    • python日志记录模块实例及改进
    • python套接字流重定向实例汇总
    • Python多线程、异步+多进程爬虫实现代码
    • Python中遍历字典过程中更改元素导致异常的解决方法
    • TensorFlow dataset.shuffle、batch、repeat的使用详解
    • Python3基础之函数用法
    • Python re模块介绍
    • 双向RNN:bidirectional_dynamic_rnn()函数的使用详解
    • Linux下为不同版本python安装第三方库

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有