python运算符and

Python operators can be divided into multiple categories. Two of them are – bitwise operators and logical operators. Bitwise operator performs operations on integers in binary format whereas logical operators perform operations on boolean values.

Python运算符可以分为多个类别。 其中两个是–按位运算符和逻辑运算符。 按位运算符对二进制格式的整数执行运算,而逻辑运算符对布尔值执行运算。

Python AND运算子 (Python AND Operator)

There are two types of Python AND Operators.

有两种类型的Python AND运算符。

  1. Bitwise AND Operator: It’s denoted by & and work with integers. The numbers are converted into binary format and bitwise AND operation is performed. Finally, the output is returned in the decimal format.按位AND运算符 :用&表示,并与整数一起使用。 将数字转换为二进制格式,然后执行按位与运算。 最后,输出以十进制格式返回。
  2. Logical AND Operator: It’s denoted by and and work with boolean values. The output is boolean – either True or False.逻辑AND运算符 :用and表示, and与布尔值一起使用。 输出为布尔值TrueFalse

Python按位与运算符示例 (Python Bitwise AND Operator Example)

Let’s look at an example of bitwise and operator. We will ask the user to enter two numbers and print their binary and operation output.

让我们看一下按位和运算符的示例。 我们将要求用户输入两个数字并打印其二进制和运算输出。

a = int(input('Please enter an integer:\n'))
b = int(input('Please enter another integer:\n'))print(f'{a} in binary is {str(bin(a))[2:]}')
print(f'{b} in binary is {str(bin(b))[2:]}')
print(f'Binary AND of {a} and {b} is {a&b}')

Output:

输出

Python And Operator – Bitwise

Python和运算符–按位

Python逻辑AND运算子范例 (Python Logical AND Operator Example)

Let’s look at an example of logical and operator. We will ask the user to enter a single digit number and print if it’s positive or negative. If the user doesn’t enter single digit integer, then we will print it too.

让我们看一个逻辑和运算符的例子。 我们将要求用户输入一个数字并打印它的正数还是负数。 如果用户没有输入一位整数,那么我们也将其打印出来。

x = int(input('Please enter a single digit integer:\n'))if x > 0 and x < 10:print('You entered positive single digit number')
elif x  -10:print('You entered negative single digit number')
else:print('You did not entered single digit integer')

Output:

输出

Python Logical And Operator

Python逻辑和运算符

摘要 (Summary)

Python provides a lot of operators to work with different kinds of data types. Here we learned how to use Python and operators with boolean and bitwise binary integers.

Python提供了许多运算符来处理不同类型的数据类型。 在这里,我们学习了如何对布尔值和按位二进制整数使用Python和运算符。

GitHub Repository.GitHub存储库中检出完整的python脚本和更多Python示例。

翻译自: https://www.journaldev.com/26700/python-and-operator

python运算符and

python运算符and_Python AND运算子相关推荐

  1. 【Python面试必看系列】之Python 中的三元运算子

    Q 4. 解释一下 Python 中的三元运算子 python中并没有c++中的三元算子 : c=a>b?a:b //意思是如果a>b就将a赋值给c,否则将b赋值给c. 但是python中 ...

  2. CrazyWing:Python自动化运维开发实战 五、Python运算符与表达式

    导语: 1.什么是运算符 2.什么是表达式 3.python运算符分类 4.python运算符优先级 什么是运算符: 运算符用于执行程序代码运算,会针对一个以上操作数项目来进行运算.例如:2+3,其操 ...

  3. [转载] 不少Gate或Node运算子 的反向传播代码

    参考链接: Python运算子 https://github.com/vinhkhuc/MemN2N-babi-python/blob/master/memn2n/nn.py

  4. matlab 运算子图_PHP运算子

    matlab 运算子图 Today we will look into PHP operators. Earlier we went through PHP tutorial for beginner ...

  5. python运算符讲解

    ♥️作者:小刘在这里 ♥️每天分享云计算网络运维课堂笔记,疫情之下,你我素未谋面,但你一定要平平安安,一  起努力,共赴美好人生! ♥️夕阳下,是最美的,绽放,愿所有的美好,再疫情结束后如约而至. 目 ...

  6. Python 运算符

    Python 运算符 运算符是一种"功能"符号,用来进行相应的运算.Python 运算符分为 算术运算符.位运算符.逻辑运算符.比较运算符.比较(关系)运算符.赋值运算符以及其他运 ...

  7. python ** 运算符_Python从入门到放弃运算符(2)

    摘要:上一篇Python从入门到放弃-运算符(1),讲了Python的运算符中的算术运算符.赋值运算符.比较(关系)运算符,这篇继续讲Python的运算符. 逻辑运算符 逻辑运算符是对真和假两种布尔值 ...

  8. python叫什么-什么叫Python运算符重载

    什么叫Python运算符重载 Python中每个数据类型都有其独特的操作方法,例如列表类型支持直接做加法操作实现添加元素的功能,字符串类型支持直接做加法实现字符串的拼接功能,也就是说,同样的运算符对于 ...

  9. python的用途-Python运算符的作用与意义

    Python运算符的作用与每个python运算符的意义 什么是运算符? 本章节主要说明Python的运算符.举个简单的例子 4 +5 = 9 . 例子中,4 和 5 被称为操作数,"+&qu ...

最新文章

  1. 毕业设计 c语言编译器的设计开发-字节代码格式设计与实现 开题报告,C语言编译器设计与实现...
  2. 理解并取证:广域网上的PPP协议
  3. 粤教版管理计算机中的文件教案,最新粤教版初中信息技术第一册教案(全册).docx...
  4. An Energy-Efficient Ant-Based Routing Algorithm for Wireless Sensor Networks (无线传感网中基于蚁群算法的能量有效路由)2
  5. hbase 页面访问_HBase
  6. 数组tostring方法_数组toString()方法以及JavaScript中的示例
  7. 《史上最简单的 SpringCloud 教程》系列
  8. oracle 查看日志组切换状态_【DB笔试面试800】在Oracle中,归档和非归档模式之间的不同点是什么?它们各自的优缺点是什么?...
  9. python写TCP协议
  10. TiDB 在 Cisco Webex 架构中的部署和应用
  11. 有什么软件可以测试游戏视频数据,免费录制游戏视频软件有哪些?看完你就知道了...
  12. linux 延迟 10 ms,网络延迟10ms怎么做到(增加网络延迟软件)
  13. 为什么外包公司这么不受欢迎??
  14. 基于TensorFlow Encrypted (TFE)的隐私计算benchmark
  15. react-native穿山甲广告android
  16. 网易称暴雪离婚不离身;苹果发布 M2 Pro 和 M2 Max 芯片;滴滴出行 App 已重新上架安卓应用商店 | 极客头条...
  17. 在 UUP dump 被墙的情况下如何用 UUP 下载 ISO 镜像
  18. A题 海岛争霸
  19. android 独立插件,最新反编译任何微信小程序,以及独立分包、插件的处理方式...
  20. 游戏本推荐排行榜哪款好?开箱这款有答案

热门文章

  1. JavaScript很牛
  2. web工程本地跟tomcat部署导致根路径不一致问题
  3. 后退与hash的问题
  4. flex怎么设置调用的外部浏览器
  5. C#获取文件夹下的所有文件名
  6. [转载] LeetCode题解(面试16.22):兰顿蚂蚁(Python)
  7. [转载] Python3入门精通基础教程(合集)
  8. element-UI 表单校验失效处理
  9. plsql本机不安装数据库连接远程数据库
  10. 如何引用XML文件生成C#类