Python Boolean类型 判断
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. 1All 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类型 判断的更多相关文章
- Python字符串类型判断错误
Python里面常用的字符串类型有str和unicode,如果要判断一个对象的类型,最好用basestring,否则可能会判断错误: str1 = "hello" str2 = u ...
- JS判断时特殊值与boolean类型的转换
扒开JQuery以及其他一些JS框架源码,常常能看到下面这样的判断,写惯了C#高级语言语法的我,一直以来没能系统的理解透这段代码. var test; //do something... if(tes ...
- 【Java】if判断boolean类型
public class Test { public static void main(String[] args) { boolean i=false; boolean j=true; if(i=j ...
- python的数据结构分类,以及数字的处理函数,类型判断
python的数据结构分类: 数值型 int:python3中都是长整形,没有大小限制,受限内存区域的大小 float:只有双精度型 complex:实数和虚数部分都是浮点型,1+1.2J bool: ...
- python学习_循环结构 and 类型判断
# 循环结构 ### 循环结构(while) - 格式 ```python while 表达式: 语句块 ``` > 执行流程:当程序执行到while语句时,首先判断表达式的真假.若表达式的值为 ...
- Python列表操作与深浅拷贝(5)——数字处理函数、类型判断、列表链表队列栈
python内建数据结构 分类 数值型: int float complex bool 序列对象: 字符串str 列表list 元组tuple 键值对: 集合set 字典dict 数值型 (list ...
- JS中字符串的true转化为boolean类型的true
var a="True"; a = eval(a.toLowerCase()); alert(typeof a); //boolean alert(a);//true 正解,eva ...
- php变量的判空和类型判断
(1)var_dump(); 判断一个变量是否已经声明并且赋值,并且打印类型和值 <?php $a; var_dump($a);//输出null <?php var_dump($a);// ...
- [改善Java代码]在equals中使用getClass进行类型判断
建议47: 在equals中使用getClass进行类型判断 本节我们继续讨论覆写equals的问题.这次我们编写一个员工Employee类继承Person类,这很正常,员工也是人嘛,而且在JEE中J ...
- JavaScript 类型判断 —— typeof 以及 instanceof 中的陷阱
JavaScript中基本类型包含Undefined.Null.Boolean.Number.String以及Object引用类型.基本类型可以通过typeof来进行检测,对象类型可以通过instan ...
随机推荐
- python 文件 写入
import sys import os # 打印当前文件的路径 print(__file__) # 打印当前文件所在文件夹的路径 print(os.path.dirname(__file__)) # ...
- Word List 2023
Word List 2023 记录 2023 年阅读论文时遇到的单词 wildcard 通配符 wildcard predicate 通配符谓词 maturation 成年过程:长大成人 ever-i ...
- A Novel Sequential Method to Train Physics Informed Neural Networks for Allen Cahn and Cahn Hilliard Equations
一种新的顺序方法去求解关于时间的方程.个人感觉论文很差.(方法不新颖,写作很无聊,排版也有问题,内容也表述不清). 本文提出一种利用单个神经网络,在连续时间段上顺序求解偏微分方程的新型方案.关键思想是 ...
- sublime json格式化
1. 插件安装 install package-->pretty json 2. 快捷键设置 设置(preference):热键设置 [ {"keys": ["al ...
- 高德地图poi关键字搜索-vue+ant-design
最近有个需求,需要输入上车点,下车点,然后输入上车点的时候还要在下方显示地图附近的车辆.百度了一波之后,完全莫得头绪,很多代码也都用不了,即便改了之后也不怎么生效.我用的是jeecg-boot.最后静 ...
- studiostyl.es网站scheme文件无法下载
原因网站引用Google的服务 解决方法:查看网页源码.选择选取页面中的元素,选择download按钮,如下图所示 downloadExisting后面的数字代表主题的ID. 在网站中输入https: ...
- fastapi loguru
使用loguru记录日志 安装 pip install loguru 基本使用 那么这个库怎么来用呢?我们先用一个实例感受下: In [1]: from loguru import logger .. ...
- httpcanary高级版--不闪退!!!!
地址 https://wwm.lanzouw.com/iOf7Hz11s4j 密码:45of
- JS学习-async/await
async/await 它保证函数的返回值为 promise. 用更少的.then()块来封装代码,同时它看起来很像同步代码 注意:可能会因为大量await的promises相继发生而变慢. asyn ...
- macOS完整安装包下载方法
Python脚本下载 开源地址:macadmin-scripts 下载installinstallmacos.py到Mac,然后用python运行,如图: # ProductID Vers ...