and 判断非Boolean类型数据会自动转换类型

"A" and "B" → "B"

因为表达式 A 和 B都为True所以返回 "B"

"A" is True → False

因为这里判断的"A": str类型,而True为Boolean类型所以不相等

bool("A") is True → True

这里将"A"装换为Boolean类型后就可以判断成功了

所以得出结论 and 关键字在做数据判断时会将其装换为Boolean类型后,再进行判断

以下是官方定义的False对象

Truth Value Testing

Any object can be tested for truth value, for use in an if or while condition or as operand of the Boolean operations below. The following values are considered false:

None

False


zero of any numeric type, for example, 0, 0L, 0.0, 0j.


any empty sequence, for example, '', (), [].


any empty mapping, for example, {}.


instances of user-defined classes, if the class defines a nonzero() or len() method, when that method returns the integer zero or bool value False. 1

All other values are considered true — so objects of many types are always true.

Operations and built-in functions that have a Boolean result always return 0 or False for false and 1 or True for true, unless otherwise stated. (Important exception: the Boolean operations or and and always return one of their operands.)

Python Boolean类型 判断的更多相关文章

  1. Python字符串类型判断错误

    Python里面常用的字符串类型有str和unicode,如果要判断一个对象的类型,最好用basestring,否则可能会判断错误: str1 = "hello" str2 = u ...

  2. JS判断时特殊值与boolean类型的转换

    扒开JQuery以及其他一些JS框架源码,常常能看到下面这样的判断,写惯了C#高级语言语法的我,一直以来没能系统的理解透这段代码. var test; //do something... if(tes ...

  3. 【Java】if判断boolean类型

    public class Test { public static void main(String[] args) { boolean i=false; boolean j=true; if(i=j ...

  4. python的数据结构分类,以及数字的处理函数,类型判断

    python的数据结构分类: 数值型 int:python3中都是长整形,没有大小限制,受限内存区域的大小 float:只有双精度型 complex:实数和虚数部分都是浮点型,1+1.2J bool: ...

  5. python学习_循环结构 and 类型判断

    # 循环结构 ### 循环结构(while) - 格式 ```python while 表达式: 语句块 ``` > 执行流程:当程序执行到while语句时,首先判断表达式的真假.若表达式的值为 ...

  6. Python列表操作与深浅拷贝(5)——数字处理函数、类型判断、列表链表队列栈

    python内建数据结构 分类 数值型: int float complex bool 序列对象: 字符串str 列表list 元组tuple 键值对: 集合set 字典dict 数值型 (list ...

  7. JS中字符串的true转化为boolean类型的true

    var a="True"; a = eval(a.toLowerCase()); alert(typeof a); //boolean alert(a);//true 正解,eva ...

  8. php变量的判空和类型判断

    (1)var_dump(); 判断一个变量是否已经声明并且赋值,并且打印类型和值 <?php $a; var_dump($a);//输出null <?php var_dump($a);// ...

  9. [改善Java代码]在equals中使用getClass进行类型判断

    建议47: 在equals中使用getClass进行类型判断 本节我们继续讨论覆写equals的问题.这次我们编写一个员工Employee类继承Person类,这很正常,员工也是人嘛,而且在JEE中J ...

  10. JavaScript 类型判断 —— typeof 以及 instanceof 中的陷阱

    JavaScript中基本类型包含Undefined.Null.Boolean.Number.String以及Object引用类型.基本类型可以通过typeof来进行检测,对象类型可以通过instan ...

随机推荐

  1. JMeter 三- Run JMeter in non-GUI mode

    Run Jmeter in non-GUI mode: 1. Swith to \Jmeter\bin 2. run "jmeter -n -t E:\JmeterforLoadGenesi ...

  2. 论文笔记:Symbolic Execution for Software Testing: Three Decades Later

    论文笔记:Symbolic Execution for Software Testing: Three Decades Later 作者 Cristian Cadar 是英国帝国理工学院SRG(Sof ...

  3. ubuntu 铺满桌面 调整字体 安装firefox中文版

    ubuntu 铺满桌面 安装 open-vm-tools sudo apt-get install open-vm-tools sudo apt-get install open-vm* . rebo ...

  4. Ubuntu16.04设置root以及root用户自动登录

    自己之前做的笔记确实不是很详细.因为像是一些环境的配置,即使是这样做,但是自己大概率下是不知道这样做的原因,所以很多东西能不能弄好是有很大的运气成分在里面.所以就很需要记录下自己到底干了些什么. 所以 ...

  5. 全国分乡镇第五次人口普查数据shp数据库省市区县街道

    ==名称:全国第五次人口普查任意十个乡镇的乡镇界地图==数据说明:精确到乡镇级别.==数据:面数据,属性列表(乡镇名.乡镇代码,第六次人口普查分乡镇属性数据)==时间:截止2000年12月31日==格 ...

  6. Nginx+Tomcat 负载均衡配置

    一.问题引入: Nginx+Tomcat 是目前主流的java web架构,如何让 nginx+tomcat 同时工作呢,也可以说如何使用 nginx 来反向代理 tomcat 后端均衡呢? 二.JA ...

  7. httpcanary高级版--不闪退!!!!

    地址 https://wwm.lanzouw.com/iOf7Hz11s4j 密码:45of

  8. Codeforces Round #781 (Div. 2) - D. GCD Guess

    GCD + 位运算 [Problem - 1665D - Codeforces](https://codeforces.com/problemset/problem/1627/D) 题意 交互题,有一 ...

  9. mysql命令行添加用户并赋予权限

    mysql> create user 'admin'@'%' identified by '123456';Query OK, 0 rows affectedmysql> FLUSH PR ...

  10. Linux基础第十一章:日志文件及如何使用rsyslog搭建小型日志服务器

    一.日志文件 1.日志作用 2.常用日志 3.日志级别 二.Rsyslog日志处理系统 1.使用Rsyslog创建日志有点 2.Rsyslog配置文件解析 3.使用rsyslog将ssh服务的日志单独 ...