python的and,or,not取值


and、or、not运算符是从左向右开始解析的


标题and:逻辑表达式从左向右解析的过程中,如果有常数(或变量)的值等于0(或false),则返回0(或false);如果不存在0(或false);则返回最后一个常数(或变量)。


```python
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900    64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()"    for more information.
   >>> 1 and 2 and 0 and 3 and 5 and 4 
   >0
   >>> 1 and 2 and 3 and 4 and 5 
   >5
   >>> 4 and 3 and 2 and 1 
   >1
   >>>

or:返回逻辑表达式从左向右解析的过程中第一个常数(或变量)的值为不等于0的常数(或变量的值)

```python

```python
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> 0 or 2 or 3 or 4 or 5
2
>>> 5 or 4 or 3 or 2 or 0
5
>>> 0 or 0 or 5 or 4 or 3
5
>>> 

not:返回布尔型的结果,表达式:not n,(其中n∈R,且n≠0),其结果为false,表达式:not 0,结果为true。

Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> not 10.10990
False
>>> not 8
False
>>> not -11.56
False
>>> not -4
False
>>> not 0
True
>>> 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值